即使在横向模式下,我也想保持我的 Imageview 的纵横比。即使我使用 scaleType :fitXY 和 adjustBounds,它看起来也 super 拉伸(stretch)这是我的 xml 文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="24dp"
android:layout_gravity="center">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:scaleType="fitXY"
android:adjustViewBounds="true"
android:id="@+id/image" />
/>
</FrameLayout>
</LinearLayout>
更新: 我使用 glide 设置我的 ImageView 。它主要是一张 640 X 330 的图像
Glide.with(this)
.load("http://www.web-cars.com/lambo_sb/IMG_3410.jpg")
.into(imageView);
最佳答案
试试这个,
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:padding="24dp">
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="@drawable/placeholder" />
/>
</FrameLayout>
</LinearLayout>
关于android - ImageView 在横向模式下被拉长,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42715310/