android - 实现带图片+文字的Button (使用FrameLayout包含View + Text, 不要使用ImageButton)
访问量: 2070
先看这个图:
注意这个Button, 它的文字不处于”全局“高度的中心,而是上面的小框的中心,所以,我们很难用ImageButton去解决。
思路是用 ImageView: , TextView 组合的方式来实现。 但是考虑到不同机型的显示,我们要把它们外层包一个FrameLayout, 这样的话,就不会出现机型不同,导致文字的位置跟预期的不一样了
下面是代码: <FrameLayout
android:layout_marginTop="70dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
>
<ImageView
android:layout_width="194dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/step_one_button"
android:scaleType="fitXY"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/bind_device_button"
android:layout_gravity="center"
android:layout_marginTop="-3dp"
android:textSize="15sp"
android:textColor="@color/selectTextColor"
/>
</FrameLayout>