23

カスタムリストビューに取り組んでいます。CheckBoxカスタムビューで表示したい。のテキストはありませんCheckBox。の右側に常にいくつかのスペースがあることがわかりましたCheckBox

これが私のレイアウトxmlファイルです:

<?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="horizontal" android:background="#fa9654"
android:paddingTop="65dp" android:paddingBottom="65dp">



<TextView android:id="@+id/bus_route_list_item_num"
    android:layout_height="wrap_content" android:layout_width="0dip"
    android:gravity="center" android:layout_gravity="center_vertical|center_horizontal"
    android:layout_weight="0.15"></TextView>

<TextView android:id="@+id/bus_route_list_item_station"
    android:layout_height="wrap_content" android:layout_width="0dip"
    android:gravity="left" android:layout_gravity="center_vertical|center_horizontal"
    android:layout_weight=".5"></TextView>


<TextView android:id="@+id/bus_route_list_item_fee"
    android:layout_height="wrap_content" android:layout_width="0dip"
    android:gravity="center" android:layout_gravity="center_vertical|center_horizontal"
    android:layout_weight=".15"></TextView>


<CheckBox android:id="@+id/bus_route_list_item_reminder" android:layout_height="wrap_content" 
    android:layout_width="0dip" android:layout_weight=".20" android:gravity="center" 
    android:layout_gravity="center" android:paddingRight="0dp" android:paddingLeft="0dp" 
    android:paddingTop="0dp" android:paddingBottom="0dp" android:background="#0066ff" 
    android:text=""
/>

</LinearLayout>

結果は次のようになります:
http://pwong.name/checkbox_problem2.jpg

ご覧のとおり、チェックボックスの右側にスペースがあります。私が欲しいのは、チェックボックスを青い領域の真ん中に置くことです。

不要なスペースを削除することは可能ですか? ありがとう

4

6 に答える 6

20

CheckBoxLinearLayout でラップしandroid:gravity="center"て、そのレイアウトで使用できます。

 <LinearLayout
    android:layout_height="wrap_content"
    android:layout_width="0dip" 
    android:layout_weight=".20"              
    android:background="#ff0000" 
    android:gravity="center">

    <CheckBox android:id="@+id/bus_route_list_item_reminder" 
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content"                     
    />

</LinearLayout>

別の方法として、 を使用できますRelativeLayout。これにより、レイアウトが大幅に簡素化され、layout_weight.

于 2011-06-15T14:00:09.040 に答える
1

ここでは相対レイアウトを使用します。親の右にチェックボックスを揃えています...

よろしく、ステファン

于 2011-06-15T14:01:58.783 に答える