2011-03-09 82 views
12

我在我的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> 

回答

30

在子视图上使用XML属性'android:duplicateParentState'设置为true以使其继承其父项的可绘制状态。

更多细节在这里:http://developer.android.com/reference/android/view/View.html#attr_android:duplicateParentState

+0

D'oh!为什么我没有发现那个属性?!非常感谢,那是我的头脑! – steemcb 2011-05-09 10:12:12

+0

WOOOOOOOOOOOOOOOW – hasan83 2015-08-31 10:04:15

+0

@ hasan83 - 大声笑....你有一个清晰的时刻? – dell116 2017-12-13 19:27:05

相关问题