android - 在 ImageView 中居中图像的问题
问题描述
我有一张图片(兔子 86*148 像素)。我有这个代码:我没用过 android:layout_gravity="center"
,android:gravity="center"
但图像在 ImageView 的中心,为什么?
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="15dp">
<ImageView
android:id="@+id/imageView3"
android:layout_width="190dp"
android:layout_height="190dp"
android:src="@drawable/rabbit" />
</LinearLayout>
现在,我有这个代码。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="15dp">
<ImageView
android:id="@+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/rabbit" />
</LinearLayout>
图像在左侧。iv.SetScaleType(ImageView.ScaleType.CenterInside)
没有效果。
解决方案
将此添加到您的布局中
android:scaleType="fitCenter"
推荐阅读
- android - 您可能无权在此组织中创建项目
- node.js - 在 node.js Express 服务器上部署 Angular Universal
- google-data-studio - 数据洞察社区连接器:结合基于时间和非时间的指标
- docker - apt-key 命令在 shell 上有效,但在 Dockerfile 上失败
- php - 空对象模式无法解决多种返回类型的问题
- regex - 评估多个正则表达式的优化
- c# - RestSharp JsonDeserializer 列表对象
- android - Java 邮件在 Marshmallow 及更高版本上失败,但在 Lollipop 及更低版本上成功
- tensorflow - MNIST分类:mean_squared_error损失函数和tanh激活函数
- python - 无法为 python 导入 tweepy