samedi 23 avril 2016

Android Custom Checkbox selector issue

I have to customize a checkbox to show 2 different state while checked, i am using the following 2 images :

enter image description here

enter image description here

My custom selector is defined as follows:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://ift.tt/nIICcg">
<item android:drawable="@drawable/favourite_normal" android:state_checked="false"/>
<item android:drawable="@drawable/favourite_choose" android:state_checked="true"/>
<item android:drawable="@drawable/favourite_normal"/>

But thing is i am not getting proper result as in the image does not fills my checkbox view properly if i change the height and width of the checkbox which i have to do to adjust. The result i am getting like this:

enter image description here

The complete layout is given below :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://ift.tt/nIICcg"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:weightSum="1">

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="74dp"
        android:background="@drawable/bottom_bav_btn">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <LinearLayout
                android:orientation="horizontal"
                android:layout_width="80dp"
                android:layout_height="match_parent"
                android:id="@+id/linearLayout">

                <ImageView
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:id="@+id/jokeListViewBackButton"
                    android:src="@drawable/back_screen_button_normal"
                    android:layout_margin="10dp" />
            </LinearLayout>

            <LinearLayout
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_toRightOf="@+id/linearLayout"
                android:layout_toLeftOf="@+id/linearLayout2"
                android:layout_toStartOf="@+id/linearLayout2"
                android:weightSum="1">

                <LinearLayout
                    android:orientation="vertical"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <TextView
                        android:layout_width="fill_parent"
                        android:layout_height="37dp"
                        android:textAppearance="?android:attr/textAppearanceLarge"
                        android:text="Large Text"
                        android:id="@+id/jokeTitleTextView"
                        android:gravity="center_vertical|center_horizontal"
                        android:textColor="@color/fontWhiteColor" />

                    <TextView
                        android:layout_width="fill_parent"
                        android:layout_height="37dp"
                        android:textAppearance="?android:attr/textAppearanceLarge"
                        android:text="0/0"
                        android:id="@+id/jokeCountTxt"
                        android:gravity="center_vertical|center_horizontal"
                        android:textColor="@color/fontWhiteColor" />
                </LinearLayout>

            </LinearLayout>

            <LinearLayout
                android:orientation="horizontal"
                android:layout_width="80dp"
                android:layout_height="match_parent"
                android:layout_alignParentTop="true"
                android:layout_alignParentRight="true"
                android:layout_alignParentEnd="true"
                android:id="@+id/linearLayout2"
                android:gravity="center_vertical|center_horizontal">

                <CheckBox
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:id="@+id/checkBox"
                    android:button="@drawable/custom_favourite_selector"
                    android:gravity="center_vertical|center_horizontal"
                    android:checked="false" />
            </LinearLayout>
        </RelativeLayout>

    </LinearLayout>


    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:weightSum="1"
        android:background="@color/listViewBody"
        android:layout_weight="0.71">

        <ScrollView
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:id="@+id/scrollView" >

            <com.gravityapps.framework.Utils.CustomTextView
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:text=""
                android:id="@+id/jokeTextView"
                android:layout_below="@+id/imageView"
                android:layout_centerHorizontal="true"
                android:gravity="center"
                android:textSize="25dp"
                android:layout_alignParentBottom="true"
                android:layout_marginRight="10dp"
                android:layout_marginLeft="10dp" />
        </ScrollView>

    </LinearLayout>

    <LinearLayout android:id="@+id/navbar"
        android:layout_width="fill_parent"
        android:layout_height="80dp"
        android:orientation="horizontal">

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@drawable/bottom_nav_back"
            android:id="@+id/prevButtonLayout"
            android:clickable="true">

            <ImageView
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:id="@+id/imageView2"
                android:background="@drawable/previous_btn_normal"
                android:layout_margin="15dp" />
        </LinearLayout>

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@drawable/bottom_nav_back"
            android:id="@+id/randPrevButtonLayout"
            android:clickable="true" >

            <ImageView
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:id="@+id/imageView3"
                android:background="@drawable/reverse_btn_normal"
                android:layout_margin="15dp" />
        </LinearLayout>

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@drawable/bottom_nav_back"
            android:id="@+id/linearLayout5"
            android:clickable="true" >

            <ImageView
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:id="@+id/imageView4"
                android:background="@drawable/copy_btn_normal"
                android:layout_margin="15dp" />
        </LinearLayout>

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@drawable/bottom_nav_back"
            android:id="@+id/linearLayout6"
            android:clickable="true" >

            <ImageView
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:id="@+id/imageView7"
                android:background="@drawable/share_btn_normal"
                android:layout_margin="15dp" />
        </LinearLayout>

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@drawable/bottom_nav_back"
            android:id="@+id/randNextButtonLayout"
            android:clickable="true" >

            <ImageView
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:id="@+id/imageView5"
                android:background="@drawable/forward_btn_normal"
                android:layout_margin="15dp" />
        </LinearLayout>

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:clickable="true"
            android:layout_weight="1"
            android:background="@drawable/bottom_nav_back"
            android:id="@+id/nextButtonLayout">

            <ImageView
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:id="@+id/imageView6"
                android:background="@drawable/next_btn_normal"
                android:layout_margin="15dp" />
        </LinearLayout>

    </LinearLayout>
</LinearLayout>

I am not sure why i am getting this result. Any help would be appreciated. Thanks




Aucun commentaire:

Enregistrer un commentaire