是否可以为我们添加的android: drawablleft图像设置边缘或填充?
当前回答
TextView有一个android:drawablePadding属性,这应该做的伎俩:
android:drawablePadding The padding between the drawables and the text. Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters). This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type. This corresponds to the global attribute resource symbol drawablePadding.
其他回答
重新制作:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="40dp"/>
<solid android:color="@android:color/white"/>
</shape>
to
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:right="@dimen/_2dp"
android:left="@dimen/_2dp"
android:bottom="@dimen/_2dp"
android:top="@dimen/_2dp"
>
<shape
xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="40dp"/>
<solid android:color="@android:color/white"/>
</shape>
</item>
</layer-list>
android:drawablePadding只会在文本和可绘制对象之间创建一个填充间隙,如果按钮足够小,可以将两者挤压在一起。如果你的按钮比组合宽度(用于drawablleft /drawableRight)或高度(用于drawableTop/drawableBottom)更宽,那么drawablePadding不会做任何事情。
我现在也在为这个问题挣扎。我的按钮很宽,图标挂在按钮的左边缘,文本在中间居中。我唯一的方法来解决这个问题,现在已经烘焙在可绘制的边缘,通过添加空白像素到画布的左边缘用photoshop。不理想,也不推荐。但这是我目前的权宜之计,短的重建TextView/按钮。
而不是按钮使用LinearLayout与ImageView和TextView里面。在子项目,如ImageView和TextView使用android:duplicateParentState="true"。
是的。使用drawablePadding,如下所示
<TextView
android:id="@+id/tvHeader"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Settings and Contents"
android:drawableLeft="@drawable/icon_success"
android:drawablePadding="10dp" />
android:drawablePadding是给可绘制图标填充最简单的方法,但你不能给特定的一侧填充,如paddingRight或paddingLeft的可绘制图标。要做到这一点,你必须深入研究。 如果你将paddingLeft或paddingRight应用到Edittext,那么它会将填充到整个Edittext以及可绘制的图标。
推荐文章
- 改变开关的“开”色
- 以编程方式将EditText的输入类型从PASSWORD更改为NORMAL,反之亦然
- 如何在隐藏和查看密码之间切换
- 在Android上调整一个大的位图文件到缩放输出文件
- 如何更改Android版本和代码版本号?
- Android Studio突然无法解析符号
- 应用程序重新启动而不是恢复
- 如何设置整个应用程序在纵向模式?
- Android中文本的阴影效果?
- 以编程方式设置TextView的布局权重
- Android -如何覆盖“后退”按钮,所以它不完成()我的活动?
- 如何从通知点击发送参数到一个活动?
- 导航目标xxx对于这个NavController是未知的
- 使用ConstraintLayout均匀间距的视图
- 文件google-services错误。模块根文件夹中缺少Json。谷歌服务插件没有它就不能正常工作。