High-end RadioButton setting in Android code

Source: Internet
Author: User

I don't know how to start the title.

 

At present, I will focus on two aspects:

 

1. Code setting @ null

// Null is not allowed here. You must set radioButton as follows. setButtonDrawable (getResources (). getDrawable (android. r. color. transparent); // For background, you can simply use nullradioButton. setBackground (null );

 

 

2. Create a control object using a layout Template

First, create an xml Script Template for the layout of a single control that contains all default parameters. This is similar to the item layout script used to create a ListView.

<?xml version="1.0" encoding="utf-8"?><RadioButton xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="0dp"    android:layout_height="wrap_content"    android:layout_gravity="center"    android:layout_weight="1"    android:background="@null"    android:button="@null"    android:drawablePadding="-20dp"    android:drawableTop="@drawable/cat" />

 

Introduce the template above through code to create a new object

RadioButton radioButton = (RadioButton) getLayoutInflater().inflate(R.layout.radiobutton, null);

 

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.