源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

Android的ImageButton当显示Drawable图片时就不显示文字

  • 时间:2022-05-31 20:15 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Android的ImageButton当显示Drawable图片时就不显示文字
很多人对 Android提供的ImageButton有个疑问,当显示Drawable图片时就不会再显示文字了,其实解决的方法有三种: [b]第一种:[/b]就是图片中就写入文字,但是这样解决会增加程序体积,同时硬编码方式会影响多国语言的发布。 [b]第二种:[/b]解决方法很简单,通过分析可以看到ImageButton的 layout,我们可以直接直接继承,添加一个TextView,对齐方式为右侧即可实现ImageButton支持文字右侧显示。 [b]第三种:[/b]更简洁效率的方法:使用Button ,然后设定Button 的 android:drawableLeft 等属性即可。示例:
[u]复制代码[/u] 代码如下:
<Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:drawableLeft="@drawable/icon" android:text="按钮" />
[b]第四种:[/b]用布局多封一层
[u]复制代码[/u] 代码如下:
<LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:id="@+id/bt"> <ImageView android:id="@+id/ib" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ringlove" android:background="#00000000" /> <TextView android:id="@+id/tv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/cs" android:paddingLeft="20px" /> </LinearLayout>
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部