Android CheckBox RadioButton picture and text spacing issues

Source: Internet
Author: User

When using a custom checkbox or RadioButton, the custom icons and text appear on different phones with different spacing, sometimes less control, and here's My custom checkbox:

XML under Layout:

<checkbox             android:id= "@+id/recharge_activity_cb"            style= "@style/customcheckboxtheme"            android: Layout_width= "Wrap_content"            android:layout_height= "wrap_content"            android:text= "I have read and agree"            Android: Textcolor= "@color/huoqiulightblackcolor"            android:checked= "true"             />

Inside the custom Style,style content is:

<!--custom checkbox--    <style name= "Customcheckboxtheme" parent= "@android: style/ Widget.CompoundButton.CheckBox ">        <item name=" Android:button "> @drawable/checkbox_style</item>        <item name= "Android:paddingleft" > @dimen/dp8</item>    </style>

The selected and unchecked pictures are called, under drawable:

<?xml version= "1.0" encoding= "Utf-8"? ><selector xmlns:android= "http://schemas.android.com/apk/res/ Android ">        <item android:state_checked=" true "android:drawable=" @drawable/agree "/>    <item Android:state_checked= "false" android:drawable= "@drawable/disagree"/>    <item android:drawable= "@ Drawable/disagree "/></selector>


Although you can display the desired on some systems by setting paddingleft, some do not.
<item name= "Android:paddingleft" > @dimen/dp8</item>

So the question is, in what way can we solve it?

Here's my solution: using the Checkedtextview control

<checkedtextview             android:id= "@+id/recharge_activity_ctv"            android:checkmark= "@drawable/checkbox_ Style "            android:layout_width=" wrap_content "            android:layout_height=" wrap_content "            android:checked=" True "            />

<textview             android:id= "@+id/buy_write_jine_agree_tv"            android:layout_width= "Wrap_content"            Android : layout_height= "wrap_content"            android:text= "I have read and agree to"            android:textcolor= "@color/huoqiulightblackcolor"            android:layout_marginleft= "@dimen/dp3"            />


Where checkmark is the top drawable. The selected state XML

android:checkmark= "@drawable/checkbox_style"

Then use ischecked () in the code to determine whether the Checkedtextview is selected, use the toggle () method to set the check and uncheck the effect, so there is no space between the icon and the text, the problem is solved perfectly!



Android CheckBox RadioButton picture and text spacing issues

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.