我有一个具有项目模板的旋转器。在内部,我有一个文本视图和一个填充布局的复选框,但它固定在左边框(请参阅图像(。在不包装内容的同时,如何使复选框中心?填充和边缘不起作用。
链接到复选框图像
项目模板布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<TextView
style="?android:attr/spinnerDropDownItemStyle"
android:background="@drawable/location_item_dash"
android:foreground="#000"
android:ellipsize="marquee"
android:singleLine="true"
android:textColor="#FFFFFF"
local:MvxBind="Text LocationName"
android:id="@+id/spinnertext"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.8" />
<CheckBox
local:MvxBind="Checked Selected"
android:background="@drawable/location_item_dash"
android:id="@+id/spinnercheck"
android:gravity="center"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.2"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_centerInParent="true" />
</LinearLayout>
</LinearLayout>
将复选框包装在另一个布局中,并在外部布局中使用中心重力。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<TextView
android:id="@+id/spinnertext"
style="?android:attr/spinnerDropDownItemStyle"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.8"
android:background="@drawable/location_item_dash"
android:ellipsize="marquee"
android:foreground="#000"
android:singleLine="true"
android:textColor="#FFFFFF"
local:MvxBind="Text LocationName" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.2"
android:gravity="center">
<CheckBox
android:id="@+id/spinnercheck"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:background="@drawable/location_item_dash"
android:gravity="center"
local:MvxBind="Checked Selected" />
</LinearLayout>
</LinearLayout>