您的位置:首页 > 其它

scaleType-模拟按钮加文字整天点击效果

2015-08-21 21:26 295 查看
经常碰到这种情况,就是一个按钮下面有文字,我们点击按钮的时候,按钮跟文字的背景都是同时变化的。我们看下下面的效果



点击以后如下



如果想要实现这个方法,网上有很多的方法,主要就是自定义控件,或者是使用textview本身提供的增加drawable方法。这里主要是使用一个偷懒的方法。使用ImageButton 跟 TextView 一起实现。虽然方法很笨,灵活性很差。但至少能实现效果。如下

<RelativeLayout
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="center" >

<ImageButton
android:id="@+id/ig"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/ic_launcher"
android:scaleType="matrix"
android:paddingLeft="80dp"
android:background="@drawable/select" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="aaaaaaa"
android:textColor="#ffffff"
android:layout_marginBottom="10dp"
android:textSize="30sp" />
</RelativeLayout>


其中主要就是

android:scaleType="matrix"


的方法

它可以把图片放到控件ImageButton的左上角。然后我们使用padding来调整图片的作用位置。就可实现imageButton 点击区域充满整个父容器了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: