mejkan mejkan - 5 months ago 19
Android Question

why custom checkbox textview overwrite on checkbox button?

enter image description here Here i am using custom checkbox but texview of checkbox overwrite button.
what i should do? i try to some padding but its work some devices fine but in some text display more left-paading, while in some overwrite what i should do?

here is xml code

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"



xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="sportsquiz.QuizActivity" >

<TextView
android:id="@+id/question_noID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />

<TextView
android:id="@+id/txt_questionID"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="TextView"
android:textAlignment="center" />

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

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#DCE3E6" >





<CheckBox
android:id="@+id/chk_ans1ID"
android:layout_width="match_parent"
android:layout_height="64dp"
android:button="@drawable/custom_checkbox"
android:onClick="onCheckboxClicked"
android:paddingLeft="50dp"
android:text="CheckBox" />

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#DCE3E6" >

<CheckBox
android:id="@+id/chk_ans2ID"
android:layout_width="match_parent"
android:layout_height="64dp"
android:button="@drawable/custom_checkbox"
android:onClick="onCheckboxClicked"
android:paddingLeft="50dp"
android:text="CheckBox" />

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#DCE3E6" >

<CheckBox
android:id="@+id/chk_ans3ID"
android:layout_width="match_parent"
android:layout_height="64dp"
android:button="@drawable/custom_checkbox"
android:onClick="onCheckboxClicked"
android:paddingLeft="50dp"
android:text="CheckBox" />

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#DCE3E6" >

<CheckBox
android:id="@+id/chk_ans4ID"
android:layout_width="match_parent"
android:layout_height="64dp"
android:button="@drawable/custom_checkbox"
android:onClick="onCheckboxClicked"
android:paddingLeft="50dp"
android:text="CheckBox" />

</LinearLayout>
</LinearLayout>

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="bottom"
android:focusable="true"
android:focusableInTouchMode="true"
android:gravity="bottom"
android:orientation="vertical" >

<ImageView
android:id="@+id/imageView_nextID"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom|right"
android:src="@drawable/circled_right" />

</LinearLayout>




please anyone help me what i am missing here

Answer

try this

  android:id="@+id/chk_ans1ID"
            android:layout_width="match_parent"
            android:layout_height="64dp"
            android:drawableLeft="@drawable/custom_checkbox"
            android:onClick="onCheckboxClicked"
            android:button="@null"
            android:drawablePadding="5dp"
            android:text="CheckBox" 
            android:background="#00000000"/>

for java code.

ans_1.setCompoundDrawablesWithIntrinsicBounds

(R.drawable.custom_checkbox_crossed, 0, 0, 0);