Padding uses a little trick in Android development

Source: Internet
Author: User

In Android app development, you sometimes use the status button (which is not the same as when you can click on a non-clickable background), and the button size required by the product is fixed. The text of the button on a different phone may appear to be abnormal (mainly when the background of the button is very easy to appear), how do we deal with it at this time? We can use the Padding property.

Look at the small example:

--------------------------just a button, but background is a state selector written in an XML file--------------------------------

 <button
            android:id= "@+id/publish_starlist_achieve_btn"
            Android:layout_width= "300DP"
            android:layout_height= "44DP"
            android:layout_centerinparent= "true"
            Android oid:layout_gravity= "Bottom"
            android:layout_margin= "10DP"
            android:background= "@drawable/common_btn_selector"
        & nbsp   android:text= "release"
            android:textcolor= "#FFFFFF"
            android:textsize= "16sp"/>

------------------------------common_btn_selector,android:state_enabled Different, corresponding drawable different--------------------------------

<?xml version= "1.0" encoding= "Utf-8"?>
<selector xmlns:android= "Http://schemas.android.com/apk/res/android" >

<item android:drawable= "@drawable/common_btn_normal" android:state_enabled= "false"/>
<item android:drawable= "@drawable/common_btn_press" android:state_pressed= "true"/>
<item android:drawable= "@drawable/common_btn_normal"/>

</selector>

In this case, in the Xiaomi 3, Xiaomi 4 and other mainstream mobile phone display no task problems, but in the cool 8297D and other models on the "release" 2 words are not displayed, and then layout file button layout added a sentence android:padding= "0DP", the problem solved.

Padding uses a little trick in Android development

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.