java - 如何在按钮中居中绘制可绘制对象?
问题描述
我想将图像(可绘制)放入按钮中。但是选项是drawableLeft/Bottom/Top/Rigth。我想把它放在中心。背景不起作用,因为它拉伸了我的图像。该图像是可绘制到可绘制文件夹中的。如果可能的话,xml中的代码。谢谢!
可绘制对象:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@drawable/im_perfil"
android:bottom="20dp"
android:left="20dp"
android:right="20dp"
android:top="20dp"/>
</layer-list>
“im_perfil”是一个 ImageAsset,
我能!我用src!
解决方案
尝试像这样使用 src 将 drawable 放入图像按钮
<ImageButton
android:id="@+id/btn_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@null"
android:src="@drawable/im_perfil" />
推荐阅读
- php - API“POST”显示成功,但不会反映数据库的更改
- azure - 获取 Azure 资源的可用性状态
- tsql - 为什么变量的值更改为 *
- ruby-on-rails - rails条件belongs_to关系
- security - SMA390 RPC 端口对面向公众的 IP 没有响应
- javafx - 为什么按钮什么都不做?javafx
- python - 在 numpy 矩阵中搜索向量
- javascript - 如何在所有浏览器的滚动视图结束时启用弹跳效果?
- c# - 在 Visual Studio 中使用 DB2 选择 N 行
- node.js - Winston - MaxListenersExceededWarning:检测到可能的 EventEmitter 内存泄漏