I'm trying to center align a checkbox in a ListView row.
Each ListView row comprises of a checkbox (left aligned) and two rows of text (to the right of the checkbox).
Any ideas on how I center the checkbox inside the row i.e. center between top and bottom dividers as opposed to top row of text?
My ListView layout is below for reference.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="5dp"
android:paddingBottom="5dp"
>
<CheckBox
android:id="@+id/cbBoxSL"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_alignParentLeft="true"
android:scaleX="1.4"
android:scaleY="1.4"
android:gravity="center_vertical"
>
</CheckBox>
<TextView
android:id="@+id/tvSLItemName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/cbBoxSL"
android:layout_marginLeft="10dp"
android:layout_alignBaseline="@+id/cbBoxSL"
android:textSize="16sp"
android:textColor="@color/aqua"
android:singleLine="true">
</TextView>
<TextView
android:id="@+id/tv_dateAdded"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tvSLItemName"
android:layout_marginLeft="10dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:textSize="12sp"
android:text="added on"
android:textStyle="italic"
android:textColor="@color/mid_grey"
android:layout_toRightOf="@id/cbBoxSL"
>
</TextView>
<TextView
android:id="@+id/tv_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tvSLItemName"
android:layout_toRightOf="@+id/tv_dateAdded"
android:textSize="12dp"
android:textStyle="bold"
android:textColor="@color/mid_grey"
android:layout_alignBaseline="@+id/tv_dateAdded"
/>
答案 0 :(得分:3)
将此行添加到您的复选框XML。
android:layout_centerVertical="true"
答案 1 :(得分:1)
尝试在复选框布局中添加android:layout_centerHorizontal="true"
或/和android:layout_centerInParent="true"