Не может иметь элемент моей дочерней строки с правой стороны в моем ExpandableListView - PullRequest
0 голосов
/ 27 марта 2012

Я создал ExpandableListView со следующим кодом:

<ExpandableListView
    android:id="@+id/android:list"
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:layout_marginTop="5dp"
    android:layout_weight="1"
    android:cacheColorHint="#00000000" /> <!-- This last line fixes a bug with a black background when scrolling through the list -->

XML, который определяет родительскую строку:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >

<TextView
    android:id="@+id/childname"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="40dp"
    android:textSize="20sp" />

</LinearLayout>

И, наконец, XML, который определяет дочернюю строкуis:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1" >

<TextView
    android:id="@+id/childname"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginLeft="60dp"
    android:layout_weight="0.80"
    android:focusable="false"
    android:textSize="14sp" />

<CheckBox
    android:id="@+id/check1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="right"
    android:layout_weight="0.2"
    android:focusable="false" />

</LinearLayout>

Я пытаюсь сделать так, чтобы CheckBox находился в самом правом углу экрана.Во время разработки, в затмении, элемент находится на самом деле справа.Но когда я устанавливаю его в свой телефон, это не так.

Вот скриншот с результатом: http://img444.imageshack.us/img444/584/97598265.png

Есть идеи, что может быть не так?

С уважением, Фелипе

ОБНОВЛЕНИЕ Следуя рекомендациям, вот что я сделал, чтобы он работал:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

<TextView
    android:id="@+id/childname"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="60dp"
    android:focusable="false"
    android:layout_centerVertical="true"
    android:textSize="14sp" />

<CheckBox
    android:id="@+id/check1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true"
    android:focusable="false" />
</RelativeLayout>

1 Ответ

1 голос
/ 27 марта 2012

Используйте относительное расположение для правильного выравнивания

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1" >

<TextView
android:id="@+id/childname"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="60dp"
android:layout_weight="0.80"
android:focusable="false"
android:textSize="14sp" />

<CheckBox
android:id="@+id/check1"
android:layout_alignParentRight="true"
android:layout_alignBottom="@id/childname"
android:layout_toRightOf="@id/childname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_weight="0.2"
android:focusable="false" />

...