2011-03-09 23 views
12

Tengo una serie anidada de diseños lineales en mi código xml. Quiero que el primer hijo del padre (también un diseño lineal) tome el foco. Hace esto si establezco enfocable en verdadero. También me gustaría pasar el foco a los niños de este diseño (para invocar sus listas de estado). Sin embargo, no pasa nada de su enfoque a sus hijos, incluso si están configurados para enfocarse. ¿Alguna idea de como hacer esto? GraciasPasar el foco de principal a secundario en Diseño lineal

<?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> 

Respuesta

30

Utilice el código XML atributo 'android: duplicateParentState' conjunto de cierto en la idea de niño para conseguir que se hereda el estado dibujable de su padre.

Más detalles aquí: http://developer.android.com/reference/android/view/View.html#attr_android:duplicateParentState

+0

D'oh! ¿Por qué no vi esa propiedad? Muchas gracias, ¡eso me estaba metiendo en la cabeza! – steemcb

+0

WOOOOOOOOOOOOOOW – hasan83

+0

@ hasan83 - lol .... ¿tuviste un momento de claridad? – dell116

Cuestiones relacionadas