Add pictures and text to the button top, bottom, left, and right positions

Source: Internet
Author: User

Reprint Please specify source: http://blog.csdn.net/droyon/article/details/37564419

A lot of people like the requirements described in the title, and most people use their own definition of components to overcome the demand, in fact, there can be more "lazy" method.

1, first attached:

2, the program.

First, Activity.java

public class Mainactivitytest extends activity{@Overrideprotected void OnCreate (Bundle savedinstancestate) { Super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main1);}}
Second, the XML layout file

<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools "android:layout_width=" match_parent "android:layout_height=" Match_parent "Android:paddi ngbottom= "@dimen/activity_vertical_margin" android:paddingleft= "@dimen/activity_horizontal_margin" Android: paddingright= "@dimen/activity_horizontal_margin" android:paddingtop= "@dimen/activity_vertical_margin" Android:o rientation= "Vertical" tools:context= ". Mainactivity "> <button android:id=" @+id/btn_ok0 "android:layout_width=" Wrap_content "Andro id:layout_height= "Wrap_content" android:drawabletop= "@drawable/ic_launcher" android:text= "@string/hello_world "/> <button android:id=" @+id/btn_ok1 "android:layout_width=" Wrap_content "Android:layo ut_height= "Wrap_content" android:drawablebottom= "@drawable/ic_launcher" android:text= "@string/hello_world"/ > <buttOn android:id= "@+id/btn_ok2" android:layout_width= "wrap_content" android:layout_height= "wrap_content         "Android:drawableleft=" @drawable/ic_launcher "android:text=" @string/hello_world "/> <button        Android:id= "@+id/btn_ok3" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android:drawableright= "@drawable/ic_launcher" android:text= "@string/hello_world"/></linearlayout>

3, analysis.

The key code is the layout file Android:drawablebottom,drawablebottom this attribute (attr) belongs to the TextView parsing category, we use the button, it inherits from TextView, You can thus use this property to complete the layout of the drawable.

Add pictures and text to the button top, bottom, left, and right positions

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.