在线性布局中将焦点从父级传递给子级
我的 xml 代码中有一系列嵌套的线性布局。我希望父级的第一个子级(也是线性布局)获得焦点。如果我将 focusable 设置为 true,它就会执行此操作。我还想将焦点传递到此布局的子级上(以便调用它们的状态列表)。然而,它不会将任何焦点传递给它的子级,即使它们被设置为可聚焦。有什么想法如何做到这一点?谢谢
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:weightSum="1"
android:layout_height="wrap_content"
android:background="@drawable/resultpage_statelist"
android:focusable="true"
android:clickable="true">
<TextView
android:text="TextView"
android:layout_height="wrap_content"
android:paddingTop="5dip"
android:paddingBottom="5dip"
android:paddingLeft="10dip"
android:layout_width="fill_parent"
android:layout_weight="0.8"
android:id="@+id/tag_row_text"
android:textSize="16dip"
android:padding="10dip"
android:textColor="@drawable/resultpage_grey_text_statelist"
android:background="#00000000"
android:focusable="true">
</TextView>
<ImageView
android:layout_height="wrap_content"
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_gravity="right|center_vertical"
android:src="@drawable/arrow_statelist"
android:layout_marginRight="10dip"
android:background="#00000000"
android:focusable="true">
</ImageView>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:background="#6E6E6E"
android:layout_height="1dip">
</LinearLayout>
</LinearLayout>
I have a nested series of linear layouts in my xml code. I want the first child of the parent (also a linear layout) to take focus. It does this if I set focusable to true. I would also like pass the focus onto the children of this layout (in order to invoke their state-lists). However it does not pass any of it's focus onto it's children, even if they are set to focusable. Any ideas how to do this? Thanks
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:weightSum="1"
android:layout_height="wrap_content"
android:background="@drawable/resultpage_statelist"
android:focusable="true"
android:clickable="true">
<TextView
android:text="TextView"
android:layout_height="wrap_content"
android:paddingTop="5dip"
android:paddingBottom="5dip"
android:paddingLeft="10dip"
android:layout_width="fill_parent"
android:layout_weight="0.8"
android:id="@+id/tag_row_text"
android:textSize="16dip"
android:padding="10dip"
android:textColor="@drawable/resultpage_grey_text_statelist"
android:background="#00000000"
android:focusable="true">
</TextView>
<ImageView
android:layout_height="wrap_content"
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_gravity="right|center_vertical"
android:src="@drawable/arrow_statelist"
android:layout_marginRight="10dip"
android:background="#00000000"
android:focusable="true">
</ImageView>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:background="#6E6E6E"
android:layout_height="1dip">
</LinearLayout>
</LinearLayout>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在子视图上使用设置为 true 的 XML 属性“android:duplicateParentState”,使其继承其父视图的可绘制状态。
更多详细信息请参见:http://developer.android.com/reference /android/view/View.html#attr_android:duplicateParentState
Use the XML attribute 'android:duplicateParentState' set to true on the child view to get it to inherit the drawable state of its parent.
More details here: http://developer.android.com/reference/android/view/View.html#attr_android:duplicateParentState