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