开发者

Radiobuttons alignment

I was making a layout that horizontally displays a checkbox, twolinelistitem which vertically consists of two textviews, textview, and lastly a radiobutton which must be on the most right edge.

However, when I finished it, somehow radiobuttons are placed more down than it should be and I have no idea how to figure out. I changed the main layout to tablelayout but nothing changed. If you don't mind, would you please help me to solve this? Below is my code and screenshot to show what happened.


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

And this is the screenshot that contains a problem:http://img684.imageshack.us/img684/3979/1134p.jpg

Thanks in advance


Put these 2 lines to the radioButton Tag

android:gravity="center"
android:layout_gravity="center_vertical"


You should also take a look at Romain Guy's post about android layouts, and how to not create wasteful layouts (especially when using them as item renderers in lists / grids).

According to that, you could restructurate your item layout, and have a more efficient one, like:

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

which also delivers you the desired output.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜