小编R. *_*ski的帖子

Android布局文件中的"工具:上下文"是什么?

从最新的ADT版本开始,我注意到布局XML文件上的这个新属性,例如:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    tools:context=".MainActivity" />
Run Code Online (Sandbox Code Playgroud)

什么是"工具:上下文"用于?

它怎么知道写在那里的活动的确切路径?它是否在清单中查看应用程序的包?

它仅限于扩展Context或仅扩展活动的类吗?它可用于ListView项目等吗?

xml android android-context android-layout android-tools-namespace

908
推荐指数
5
解决办法
23万
查看次数

什么是'app'Android XML命名空间?

这是app我从res/menu/main.xml文件中看到的命名空间的示例

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity" >
<item android:id="@+id/action_settings"
    android:title="@string/action_settings"
    android:orderInCategory="100"
    app:showAsAction="never" />
</menu>
Run Code Online (Sandbox Code Playgroud)

app命名空间的用途是什么?它是"标准"Android XML命名空间吗?是否有相同的值选项可用于放置在两个不同命名空间中的相同属性(例如app:showAsAction和android:showAsAction).

来自文档: android:showAsAction=["ifRoom" | "never" | "withText" | "always" | "collapseActionView"]

即,如果属性是相反的,上面示例中的行是否意味着其他内容:

android:showAsAction="never"
Run Code Online (Sandbox Code Playgroud)

它几乎看起来可能是某种"子类化"机制,但我似乎无法app从Google/Android源代码中找到关于命名空间的任何真实文档.

xml android xml-namespaces android-layout android-tools-namespace

159
推荐指数
1
解决办法
7万
查看次数

在Intellij IDEA/Android Studio中使用合并根标签预览布局

让我们假设我们正在开发基于LinearLayout的复合组件.所以,我们创建这样的类:

public class SomeView extends LinearLayout {
    public SomeView(Context context, AttributeSet attrs) {
        super(context, attrs);

        setOrientation(LinearLayout.VERTICAL);
        View.inflate(context, R.layout.somelayout, this);
    }
}
Run Code Online (Sandbox Code Playgroud)

如果我们将使用它LinearLayout作为根somelayout.xml,我们将有额外的视图级别,所以我们使用merge标记:

<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Some text"
        android:textSize="20sp"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Some other text"/>
</merge>
Run Code Online (Sandbox Code Playgroud)

但是在IDE中的预览选项卡中,合并始终充当FrameLayout,我们会看到类似的东西: 合并预览

(这是Android Studio,Intellij IDEA也一样,关于Eclipse我不知道)

预览加快了布局的开发速度,即使对于某些布局,它也会失去如此大的帮助.可能有一种方法可以指定,预览应该如何解释merge特定布局中的标签?

android intellij-idea android-layout android-studio android-tools-namespace

146
推荐指数
2
解决办法
2万
查看次数

工具命名空间属性,用于在设计时显示ViewPager中的布局

该工具命名空间可用于显示在布局设计视图属性.

例如,使用tools:listItem="@layout/{custom_layout}它可以在Android Studio设计器中显示具有自定义行布局的列表.

问题是:

是否可以在里面显示布局ViewPager?

android android-layout android-viewpager android-tools-namespace

30
推荐指数
1
解决办法
3989
查看次数

Android XML布局中xmlns:tools的含义是什么?

例如,在:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
...
Run Code Online (Sandbox Code Playgroud)

我需要把它吗?

xml android android-layout android-tools-namespace

27
推荐指数
2
解决办法
3万
查看次数

工具的用途是什么:从向导创建DrawerLayout(使用NavigationView)时openDrawer ="start"?

在Android Studio中使用导航抽屉创建活动会导致其显示在XML代码中:

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">
Run Code Online (Sandbox Code Playgroud)

如果我删除了tools:openDrawer="start"布局预览,导航抽屉将关闭而不是打开.

我认为这是一个替换属性,类似于android:text可以替换tools:text为在布局预览中放置一些占位符文本.但是当我将其更改为android:openDrawer或时app:openDrawer,无法编译应用程序,因为它们是未知属性.

所以我想知道tools:openDrawer它是如何工作的,以及是否记录在任何地方.

android android-studio navigation-drawer android-navigationview android-tools-namespace

15
推荐指数
2
解决办法
6511
查看次数

Android XML有没有办法将工具命名空间与自定义属性一起使用?

我已经创建了一个带属性的自定义视图.有没有办法在Android工作室中使用Android工具的那些属性?

例如 :

<MyOwnCoolView
    android:layout_width="96dp"
    android:layout_height="96dp"
    android:padding="3dp"
    tools:dividerAngle="2"/>
Run Code Online (Sandbox Code Playgroud)

attr文件的位置是:

<resources>
<declare-styleable name="MyOwnCoolView">
    <attr name="dividerAngle" format="float"/>
</declare-styleable>
Run Code Online (Sandbox Code Playgroud)

android android-layout android-xml android-view android-tools-namespace

12
推荐指数
1
解决办法
1366
查看次数

Android:如何使用包含布局的工具

我如何使用工具:

xmlns:tools="http://schemas.android.com/tools"
Run Code Online (Sandbox Code Playgroud)

用<include>?

我有一个布局A,我使用工具用测试数据填充所有文本字段.我有布局B使用include到布局中的复制它.但是,当我这样做时,我没有看到测试数据A.

如何查看A包含的测试数据B?

*两种布局都有xmlns:tools="http://schemas.android.com/tools,我甚至把它推到了布局标签上.

xml android android-layout android-tools-namespace

11
推荐指数
1
解决办法
9216
查看次数

是否有RxJava等效的Handler.postDelayed(Runnable r,long delayMillis)

我试图调用一个返回void(Java原始类型)的方法.我想延迟调用一个预定义的毫秒数.我知道这可以简单地使用Handler我喜欢不使用它.

我试着这样做:

Observable.just(getView().setAttachments(attachments)).delay(50, TimeUnit.MILLISECONDS);
Run Code Online (Sandbox Code Playgroud)

但是,有一个编译错误,即:

Observable.just(java.lang.Void) cannot be applied to (void)
Run Code Online (Sandbox Code Playgroud)

还有另外一种方法吗?我不想使用的原因Handler是代码是在Presenter(MVP模式)中定义的,我不想在仅Java类中使用Android特定代码.我更喜欢它是一个冷的Observable,因为我不必订阅它,只调用一次方法.

java mvp multithreading android rx-java

11
推荐指数
1
解决办法
6026
查看次数

RecyclerView java.lang.IndexOutOfBoundsException:检测到不一致.从添加的片段恢复时无效的项目位置

你们能帮助我吗?

这是我添加片段的代码

mRecyclerView.addOnItemTouchListener(
    new RecyclerItemClickListener(getActivity(), new RecyclerItemClickListener.OnItemClickListener() {
        @Override
        public void onItemClick(View view, int position) {
            if (!IsScrolling) {
                Fragment fragment = new ProductInfoFragment();
                    Bundle bundle = new Bundle();
                    bundle.putString("prodID", mItems.get(position).getproductID());
                    bundle.putString("catName", catName);
                    fragment.setArguments(bundle);
                    FragmentManager fragmentManager = getActivity().getFragmentManager();
                    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
                                        fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
                                        fragmentTransaction.add(R.id.fragmentContainer, fragment, "ProuctInfoFragment");
                                        fragmentTransaction.addToBackStack(null);
                                        fragmentTransaction.commit();
                                        mItems.clear();
                                    }

                                }

                            })
                    );
Run Code Online (Sandbox Code Playgroud)

但是,当我从添加的片段中按回来时,我收到此错误并且我的应用程序崩溃了.

FATAL EXCEPTION: main Process: com.tiseno.poplook, PID: 2617
 java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position 5(offset:5).state:9
      at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4401)
      at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4359)
      at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1961)
      at android.support.v7.widget.GridLayoutManager.layoutChunk(GridLayoutManager.java:438)
      at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1333)
      at android.support.v7.widget.LinearLayoutManager.scrollBy(LinearLayoutManager.java:1161) …
Run Code Online (Sandbox Code Playgroud)

android android-recyclerview

10
推荐指数
2
解决办法
1万
查看次数