【发布时间】:2017-02-04 12:50:11
【问题描述】:
我有activity_choose_number1.xml
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_choose_number1" />
这是 content_choose_number1.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.abc.abc.ChooseNumber1"
tools:showIn="@layout/activity_choose_number1">
<ListView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:id="@+id/listViewNumberList"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp" />
</LinearLayout>
这是 secnumsinglechoice.xml
<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:checkMark="@null"
android:drawableStart="?android:attr/listChoiceIndicatorSingle"
tools:targetApi="ice_cream_sandwich"
android:textSize="25dp"
android:linksClickable="false"
android:checked="false"
android:paddingTop="20dp"
android:paddingBottom="20dp" />
secnumsinglechoice.xml 是 android.R.layout.simple_list_item_single_choice 的复制粘贴并进行了一些更改。
现在我需要将 secnumusingchoice.xml 的复选框和文本居中对齐。我还需要复选框位于列表视图中每个项目的文本左侧
我尝试过的事情 1)如果我做drawableLeft,它会在文本和复选框之间创建空间,但不会使两者都居中 2)如果我添加 android:textAlignment="center" 那么它仍然居中对齐文本而不是复选框。 3) 我在这里尝试过center text and checkmark of CheckedTextView,但我想在这里尝试更多代码。
请帮忙。谢谢。
【问题讨论】:
-
为什么不分别使用
checkbox和textview?尝试使用CheckedTextView很难对齐复选框和文本.. -
@MikeM。是的,我试过了,还是不行。
-
@ roshanshan如果我单独使用我如何在选择相应的复选框时选择文本值?你能提供一些参考链接吗?谢谢。
-
@MikeM。在这个问题中,您会看到右侧的刻度线。它不像文本那样居中对齐。我希望我的文本和刻度线都居中对齐。
-
@MikeM。您能否提供代码作为答案?
标签: android xml android-layout checkbox checkedtextview