手机
当前位置:查字典教程网 >编程开发 >安卓软件开发 >Android的ImageButton当显示Drawable图片时就不显示文字
Android的ImageButton当显示Drawable图片时就不显示文字
摘要:很多人对Android提供的ImageButton有个疑问,当显示Drawable图片时就不会再显示文字了,其实解决的方法有三种:第一种:就...

很多人对 Android提供的ImageButton有个疑问,当显示Drawable图片时就不会再显示文字了,其实解决的方法有三种:

第一种:就是图片中就写入文字,但是这样解决会增加程序体积,同时硬编码方式会影响多国语言的发布。

第二种:解决方法很简单,通过分析可以看到ImageButton的 layout,我们可以直接直接继承,添加一个TextView,对齐方式为右侧即可实现ImageButton支持文字右侧显示。

第三种:更简洁效率的方法:使用Button ,然后设定Button 的 android:drawableLeft 等属性即可。示例:

复制代码 代码如下:

<Button

android:id="@+id/button1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:drawableLeft="@drawable/icon"

android:text="按钮"

/>

第四种:用布局多封一层

复制代码 代码如下:

<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>

【Android的ImageButton当显示Drawable图片时就不显示文字】相关文章:

Android调用google地图生成路线图实现代码

Android 显示和隐藏输入法实现代码

Android 自定义标题栏 显示网页加载进度的方法实例

android 实现圆角图片解决方案

Android开发笔记之:Handler Runnable与Thread的区别详解

Android 异步加载图片的实例代码

android 比较靠谱的图片压缩

Android的Touch事件处理机制介绍

Android中设置只有程序第一次运行才显示的界面实现思路

android imageview图片居中技巧应用

精品推荐
分类导航