如何解决(Android Image View) 去除背景后如何调整src的大小?
去除背景后如何调整src的大小?
使用代码imageview.setBackgroundResource(R.drawable.player_background)
After I remove the background in code
使用代码imageview.setBackground(null) or imageview.setBackgroundResource(0)
如何解决?
XML 代码
<ImageView
android:id="@+id/game_board_x0y4"
android:layout_width="45dp"
android:layout_height="45dp"
android:contentDescription="@string/game_icon_text"
app:layout_constraintBottom_toBottomOf="@+id/game_board"
app:layout_constraintEnd_toEndOf="@+id/game_board"
app:layout_constraintHorizontal_bias="0.015"
app:layout_constraintStart_toStartOf="@+id/game_board"
app:layout_constraintTop_toTopOf="@+id/game_board"
app:layout_constraintVertical_bias="0.79"
app:srcCompat="@drawable/player" />
解决方法
我认为您已将 ImageView 值的值设置为
android:layout_width="wrap_content"
android:layout_height="wrap_content"
相反,将其更改为比图像的原始大小略小的特定值
android:layout_width="40dp"
android:layout_height="40dp"
scaleType: fitXY //add this line to fit the image uniformly in the given size
这将负责调整图像大小。
编辑1:
使用 android:scaleType="center"
或 android:scaleType="matrix"
在图像视图中禁用缩放。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。