标签:
需求:准确控制Text的高度,pressed时候,同时改变背景和text的样式。
用Button的话,不能准确控制text的高度。
用Image+TextView叠加的话,pressed时候,onClick事件会被两者中一个consume,因此text的样式,背景只能改变其中之一,代码中设置也很不方便。
目前比较好的实现:
Layout+TextView。监听layout即可。
<android.support.percent.PercentRelativeLayout
android:id="@+id/layout_cancel"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_centerVertical="true"
android:background="@drawable/bg_goto_setting_white"
app:layout_heightPercent="60%"
app:layout_marginLeftPercent="6.5%"
app:layout_widthPercent="42%">
<cc.makeblock.customview.FitHeightTextView
android:id="@+id/tv_cancel"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_centerVertical="true"
android:gravity="center"
android:text="稍后再说"
android:textColor="@color/color_text_black"
app:layout_heightPercent="60%"
/>
</android.support.percent.PercentRelativeLayout>
Android:pressed状态下,改变背景和Text样式
标签:
原文地址:http://www.cnblogs.com/makebetter/p/5718843.html