android:duplicateParentState指的是当前控件是否跟随父控件的(点击、焦点等)状态
例:假设一Layout有两子View,对Layout进行监听点击事件;子ViewA一个设置duplicateParentState为true,子View设置为false,当点击Layout后,子ViewA的点击态背景变色成功,子ViewB背景态变色无效,因为点击事件被Layout捕获。效果如下图:
- <RelativeLayout
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:minHeight="44dp"
- android:id="@+id/finger_memo"
- android:background="@drawable/setting_bottom" >
- <RelativeLayout android:layout_width="wrap_content"
- android:layout_height="44dp"
- android:layout_alignParentLeft="true"
- android:layout_centerVertical="true"
- android:duplicateParentState="false"
- android:gravity="top"
- android:id="@+id/txt_memo"
- android:paddingTop="10.5dp"
- android:paddingBottom="10.5dp">
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:id="@+id/txt_finger_memo"
- android:layout_alignParentTop="true"
- android:includeFontPadding="false"
- android:text="@string/info_troopintro"
- android:layout_marginLeft="12dp"
- android:minWidth="74dp"
- android:textColor="@color/color_777777_white"
- android:duplicateParentState="false"
- android:textSize="15sp" />
- </RelativeLayout>
- <ImageView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:id="@+id/open_arrow"
- android:layout_alignParentRight="true"
- android:layout_centerVertical="true"
- android:layout_marginLeft="16dp"
- android:layout_marginRight="12dp"
- android:src="@drawable/arrow_right_gray_white" />
- <RelativeLayout android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_centerVertical="true"
- android:layout_toLeftOf="@id/open_arrow"
- android:layout_toRightOf="@id/txt_memo"
- android:duplicateParentState="true"
- android:paddingTop="10.5dp"
- android:paddingLeft="10.5dp"
- android:paddingBottom="10.5dp">
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:id="@+id/txt_finger_memo_content"
- android:layout_gravity="center_vertical|left"
- android:includeFontPadding="false"
- android:textColor="@color/color_333333_white"
- android:text="@string/content"
- android:duplicateParentState="true"
- android:textSize="15sp"/>
- </RelativeLayout>
- </RelativeLayout>
- <p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;">1)xml中与像素有关的单位</p><div><ol style="margin: 5px 0px 5px 40px; padding: 0px;"><li>px(像素):屏幕上的点。 </li><li>in(英寸):长度单位。 </li><li>mm(毫米):长度单位。 </li><li>pt(磅):1/72英寸。 </li><li>dp(与密度无关的像素):一种基于屏幕密度的抽象单位。在每英寸160点的显示器上,1dp = 1px。 在大于160点的显示器上可能增大。 </li><li>dip:与dp相同,多用于Google示例中。 </li><li>sp(与刻度无关的像素):与dp类似,但是可以根据用户的字体大小首选项进行缩放。 </li></ol></div><wbr>
- 2)是否复制它的父布局的状态<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;">在xml文件中添加如下属性:
- android:duplicateParentState="true"</p><p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;">当这个属性设置为"true"时,这个控件将优先从它的直接父控件获得当前的图片状态(例如,focused, pressed等等)。
- 对应java代码中的方法:
- isDuplicateParentStateEnabled()</p>
- </wbr>