@act262
2017-08-10T05:40:39.000000Z
字数 2034
阅读 1189
Training
编辑器面板的右侧可以查看代码“干净”程度,如果出现大量黄色的标记就需要注意了,如果是红色标记那就更大问题了。
tools
命名空间tools:ignore
,抑制Lint的警告
常用到的几个属性
tools:ignore="HardcodedText"
tools:ignore="RtlHardcoded,RtlSymmetry"
tools:ignore="ContentDescription"
tools:ignore="UseCompoundDrawables"
tools:ignore="ALL"
tools:context
,关联到当前的ActivityonClick
事件
<LinearLayout 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"
android:orientation="vertical"
tools:context="com.jfz.training1.BindThemeActivity">
...
</LinearLayout>
Ctrl+Alt+Home
tools:xx
,Design-time 属性,只作用在预览时,不会影响运行时
在运行时该按钮是GONE的,但是为了方便在预览时看到效果,使用对应的`tools:xx`属性来展示
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button"
android:visibility="gone"
tools:visibility="visible" />
tools:layout
用在布局中fragment
节点的预览效果
<fragment
android:name="com.jfz.training1.LayoutFragment"
class="com.jfz.training1.LayoutFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout="@layout/fragment_layout" />
tools:listitem
、tools:listheader
、tools:listfooter
列表布局的预览常用在ListView、RecyclerView中做预览效果,listheader、listfooter在RecyvlerView中无效
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:dividerHeight="10dp"
tools:listfooter="@layout/item_list_footer"
tools:listheader="@layout/item_list_header"
tools:listitem="@layout/item_list_type" />
注意:必须指定id才能有效果,listfooter可能看不到预览效果
tools:showIn
用在被include的布局中做预览效果Ctrl+Shift+A
搜索相关的Color Picker
打开IDEA自带的取色工具参考:
https://developer.android.com/studio/write/tool-attributes.html
http://yanghui.name/blog/2015/08/31/tools-namespace-and-support-library-annotations/