Android中Button

1.android:drawableTop="@drawable/accept"设置在按钮文本的上面绘制指定图片。可同时指定drawableLeft等其它方向

2.android:drawablePadding="30dp"设置在按钮文本与图片间距

3.ImageButton无法实现文字与图片同时显示的效果,Button则可以,设置 android:text="按钮5"  android:background="@drawable/add"

4.android:layout_toLeftOf="@id/comments_list_reply_zhan"实现在哪个控件的左侧

5.style="@style/main_tab_bottom" 当一个样式属性太多时,放到专门的文件styles.xml中引用

 <style name="main_tab_bottom">
        <item name="android:textSize">12.0dip</item>
        <item name="android:ellipsize">marquee</item>
        <item name="android:gravity">center_horizontal</item>
        <item name="android:background">@drawable/home_btn_bg</item>
        <item name="android:paddingTop">5.0dip</item>
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:button">@null</item>
        <item name="android:singleLine">true</item>
        <item name="android:drawablePadding">2.0dip</item>
        <item name="android:layout_weight">1.0</item>
    </style>

 <item name="android:background">@drawable/home_btn_bg</item>是设置按钮的动作效果

drawable文件夹中的home_btn_bg.xml文件中

<selector xmlns:android="http://schemas.android.com/apk/res/android">

 <item android:drawable="@drawable/newsdetails_titlebar_btn_previous" android:state_pressed="false"/>    

<item android:drawable="@drawable/newsdetails_titlebar_btn_previous_selected" android:state_pressed="true"/>    

<item android:drawable="@drawable/newsdetails_titlebar_btn_previous_selected" android:state_focused="true"/>    

<item android:drawable="@drawable/newsdetails_titlebar_btn_previous"/>

</selector>

newsdetails_titlebar_btn_previous为原图片,newsdetails_titlebar_btn_previous_selected为按下的图片

 layout_gravity:本控件在它父控件中的相对位置

gravity:本控件中的内容在本控件中的相对位置

作者:欢醉
公众号【一个码农的日常】 技术群:319931204 1号群: 437802986 2号群: 340250479
出处:http://zhangs1986.cnblogs.com/
码云:https://gitee.com/huanzui
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
Top
原文地址:https://www.cnblogs.com/zhangs1986/p/2869856.html