是否可以为我们添加的android: drawablleft图像设置边缘或填充?
当前回答
@Bhargav Thanki表示:
android:drawablePadding是最简单的填充方法 可绘制图标,但你不能给特定的一侧填充像 可绘制图标的右或左填充。为了实现这个目标 必须深入调查。如果你应用左填充或右填充 到EditText,然后它将放置填充到整个EditText 与可绘制的图标。
例子:
<TextView
android:layout_width="match_parent"
android:padding="5dp"
android:id="@+id/date"
android:gravity="center|start"
android:drawableEnd="@drawable/ic_calendar"
android:background="@drawable/edit_background"
android:hint="Not Selected"
android:drawablePadding="10dp"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:textColor="@color/black"
android:layout_height="wrap_content"/>
其他回答
重新制作:
<?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>
是的。使用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" />
另一个简单的解决方案可以通过嵌入layerlist实现
layered_drawable
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<inset
android:insetRight="30dp"
android:drawable="@drawable/ic_air_date">
</inset>
</item>
</layer-list>
XML中的按钮
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/layered_drawable"
android:text="something" />
textView.setCompoundDrawablesWithIntrinsicBounds(AppCompatResources.getDrawable(this,drawable),null,null,null);
addressTitleView.setCompoundDrawablePadding();
尝试使用负填充
如:
android:paddingLeft="-8dp"
推荐文章
- 改变开关的“开”色
- 以编程方式将EditText的输入类型从PASSWORD更改为NORMAL,反之亦然
- 如何在隐藏和查看密码之间切换
- 在Android上调整一个大的位图文件到缩放输出文件
- 如何更改Android版本和代码版本号?
- Android Studio突然无法解析符号
- 应用程序重新启动而不是恢复
- 如何设置整个应用程序在纵向模式?
- Android中文本的阴影效果?
- 以编程方式设置TextView的布局权重
- Android -如何覆盖“后退”按钮,所以它不完成()我的活动?
- 如何从通知点击发送参数到一个活动?
- 导航目标xxx对于这个NavController是未知的
- 使用ConstraintLayout均匀间距的视图
- 文件google-services错误。模块根文件夹中缺少Json。谷歌服务插件没有它就不能正常工作。