从最新的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
当我将RecyclerView添加到布局时,它显示为空白屏幕.有没有办法,比如通过tools名称空间,来显示RecyclerView内容的预览?
android android-studio android-recyclerview android-tools-namespace
这是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
让我们假设我们正在开发基于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
我刚刚将Android Studio更新到版本2.3(金丝雀版本)和最后的构建工具'com.android.tools.build:gradle:2.3.0-alpha1',当我打开布局并编写tools:并按下ctrl + space以自动完成它时,我发现了新的工具命名空间:
tools:mockup
tools:mockup_crop
tools:mockup_opacity
Run Code Online (Sandbox Code Playgroud)
我以前从未见过它们并在谷歌搜索,但我什么都没发现.它们有什么用?
recyclerview布局定义为
<android.support.v7.widget.RecyclerView
android:layout_marginTop="15dp"
android:id="@+id/call_detail_list"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:listitem="@layout/call_item"
/>
Run Code Online (Sandbox Code Playgroud)
在预览中,我可以看到指定布局中的列表项,但项目数是10.有什么方法可以更改吗?
android android-layout android-studio android-tools-namespace
该工具命名空间可用于显示在布局设计视图属性.
例如,使用tools:listItem="@layout/{custom_layout}它可以在Android Studio设计器中显示具有自定义行布局的列表.
问题是:
是否可以在里面显示布局
ViewPager?
android android-layout android-viewpager android-tools-namespace
例如,在:
<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)
我需要把它吗?
在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
我已经创建了一个带属性的自定义视图.有没有办法在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