Выравнивание радиокнопок - PullRequest
1 голос
/ 22 апреля 2011

Я делал макет, который горизонтально отображает флажок, twolinelistitem, который по вертикали состоит из двух текстовых представлений, текстового просмотра и, наконец, радиокнопки, которая должна быть на самом правом краю.

Однако, когда я закончил, радиокнопки как-то расставлены больше, чем должно быть, и я понятия не имею, как это выяснить. Я изменил основной макет на tablelayout, но ничего не изменилось. Если вы не возражаете, не могли бы вы помочь мне решить это? Ниже мой код и скриншот, чтобы показать, что произошло.


<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="horizontal"
  android:layout_width="match_parent"
  android:layout_height="wrap_content">
    <CheckBox android:layout_height="wrap_content" android:layout_width="wrap_content" 
        android:id="@+id/checkBox1" />
    <TwoLineListItem android:id="@+id/twoLineListItem1" 
        android:layout_weight="1"
        android:paddingTop="10px"
        android:layout_width="wrap_content" android:layout_height="wrap_content">
        <TextView android:id="@+id/textView1" 
                android:text="TextView"
                android:layout_width="wrap_content" android:layout_height="wrap_content" 
                android:textAppearance="?android:attr/textAppearanceMedium" />
        <TextView android:id="@+id/textView2" 
                android:text="TextView"
                android:layout_width="wrap_content" android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceSmall" 
                android:paddingTop="30px"/>
    </TwoLineListItem>
    <TextView android:text="TextView" 
        android:id="@+id/textView3" 
        android:layout_weight="1"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:paddingTop="10px"/>
    <RadioButton android:id="@+id/radioButton1" 
            android:gravity="right"
            android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>

И это скриншот, который содержит проблему: http://img684.imageshack.us/img684/3979/1134p.jpg

Заранее спасибо

Ответы [ 2 ]

4 голосов
/ 22 апреля 2011

Поместите эти 2 строки в тег RadioButton

android:gravity="center"
android:layout_gravity="center_vertical"
1 голос
/ 22 апреля 2011

Вам также следует взглянуть на сообщение Ромена Гая о макетах Android и о том, как не создавать ненужные макеты (особенно при использовании их в качестве средств визуализации элементов в списках / сетках).

В соответствии с этим, вы можете реструктурировать макет вашего предмета и иметь более эффективный, например:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <CheckBox android:id="@+id/checkBox1"
        android:layout_height="wrap_content" android:layout_width="wrap_content"
        android:layout_alignParentLeft="true" android:layout_centerVertical="true" />
    <RadioButton android:id="@+id/radioButton1"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:layout_alignParentRight="true" android:layout_centerVertical="true" />
    <TextView android:text="@string/label_details" android:id="@+id/textView3"
        android:layout_width="wrap_content" android:layout_height="wrap_content" 
        android:layout_toLeftOf="@id/radioButton1"
        android:layout_centerVertical="true" android:minWidth="50dp" android:maxLines="1" />
    <TextView android:id="@+id/textView1" android:text="@string/loremipsum2"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:layout_toLeftOf="@id/textView3" android:layout_toRightOf="@id/checkBox1" 
        android:minWidth="50dp" android:maxLines="1" />
    <TextView android:id="@+id/textView2" android:text="@string/loremipsum2"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:layout_alignLeft="@id/textView1" android:layout_alignRight="@id/textView1"
        android:layout_below="@id/textView1" android:minWidth="50dp" android:maxLines="1" />
</RelativeLayout>

, который также обеспечивает желаемый результат.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...