lundi 26 septembre 2016

How to center the checkbox and text of checkedTextView in android?

I have 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" />

This is content_choose_number1.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://ift.tt/nIICcg"
    xmlns:app="http://ift.tt/GEGVYd"
    xmlns:tools="http://ift.tt/LrGmb4"
    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>

This is secnumsinglechoice.xml

<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://ift.tt/nIICcg"
    xmlns:tools="http://ift.tt/LrGmb4"
    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" />

The secnumsinglechoice.xml is copy paste of android.R.layout.simple_list_item_single_choice and made some changes.

Now what I need is to center align the checkbox and text of secnumusingchoice.xml. I also need the checkbox to be left side of text in each item of list view

Things I tried 1) If I do drawableLeft, it creates space between text and checkbox, but doesn't make both to be centered 2) If I add android:textAlignment="center" then still it center aligns the text but not the check box . 3) I tried here center text and checkmark of CheckedTextView but I would like to try here with more code.

Please help. Thanks.




Aucun commentaire:

Enregistrer un commentaire