RadioButton resolving text with Drawableleft and text is not centered

Source: Internet
Author: User

/** * Resolve text with drawableleft and text without centering. To set android:background= "@null" android:button= "@null" * @author Zhousheng * */public class Mdmradiobutton extends Radiobu Tton {public Mdmradiobutton (context context, AttributeSet attrs, int defstyle) {Super (context, attrs, defstyle);//TODO Au To-generated Constructor Stub}public Mdmradiobutton (context context, AttributeSet Attrs) {Super (context, attrs);//TODO Auto-generated Constructor Stub}public Mdmradiobutton (context context) {super (context);//TODO auto-generated constructor stub} @Overrideprotected void OnDraw (canvas canvas) {//Get picture of settings drawable[] Drawables = Getcompounddrawables () if (drawables! = null) {//The first is leftdrawable drawableleft = drawables[0];if (drawableleft! = null) {//Gets the width of the text float Textwidt h = Getpaint (). Measuretext (GetText (). toString ()); int drawablepadding = getcompounddrawablepadding (); int Drawablewidth = 0;drawablewidth = Drawableleft.getintrinsicwidth (); float bodywidth = textWidth + drawablewidth + drawable Padding;int y = getwidth (); CANvas.translate ((GetWidth ()-bodywidth)/2, 0);}} Super.ondraw (canvas);}}


Use:

<com.maidoumi.merchant.widget.mdmradiobutton
Android:id= "@+id/rb_main_table"
style= "@style/main_radiobtn_style"
Android:checked= "true"
android:drawableleft= "@drawable/ic_back"
android:text= "@string/main_table"/>



RadioButton resolving text with Drawableleft and text is not centered

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.