android - ImageView 在横向模式下被拉长

标签 android imageview aspect-ratio

即使在横向模式下,我也想保持我的 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/

相关文章:

android - 降级 Android SDK( api 23 -> api 21)

android - Google Sign-In for Android 中的问题

android - 如何在imageview中获取图像边缘x/y位置

java - 如何指定占位符图像?

android - Imageview动画从滑动手势开始

html - 将 div 高度设置为 100% 会导致高度为零

Android Studio 在提交更改对话框中显示未更改的文件

Android SDK 和 AVD 管理器错误 : File not found: C:\Program Files (x86)\Android\android-sdk\temp\

youtube - 如何将 mp4 纵横比更改为 16 :9 using ffmpeg?

css - 自动调整 Web 应用程序的高度和宽度