繁体   English   中英

ImageView在横向模式下变得越来越大

[英]ImageView is getting stretched out in landscape mode

我想在横向模式下保持我的Imageview的宽高比。即使我使用scaleType,它也看起来超拉伸:fitXY和adjustBounds这是我的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>

更新:我使用滑行设置我的imageview。 它主要是640 X 330图像

       Glide.with(this)
            .load("http://www.web-cars.com/lambo_sb/IMG_3410.jpg")
            .into(imageView);

使用PercentFrameLayout https://developer.android.com/reference/android/support/percent/PercentFrameLayout.html

为纵向和横向配置创建两个布局文件

肖像

<android.support.percent.PercentFrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

  <ImageView
      app:layout_aspectRatio="136%"
      app:layout_widthPercent="100%"
      android:layout_gravity="center"
      tools:ignore="ContentDescription"
      tools:src="@color/accent"
      />

</android.support.percent.PercentFrameLayout>

景观

<android.support.percent.PercentFrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

  <ImageView
      app:layout_aspectRatio="136%"
      app:layout_heightPercent="100%"
      android:layout_gravity="center"
      tools:ignore="ContentDescription"
      tools:src="@color/accent"
      />

</android.support.percent.PercentFrameLayout>

试试这个,

    <?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>

这不相关,但如果你不想在AndroidManifest.xml文件中设置所有横向模式来活动android:screenOrientation="portrait"那么你就不会进入景观模式

我认为当您不确定服务器的图像大小时,这将解决您的问题。

Glide.with(this)
                .load("http://www.web-cars.com/lambo_sb/IMG_3410.jpg")
                .centerCrop()
                .override(200, 200)
                .into(imgView);

- 图像调整大小和裁剪您不确定从远程服务器加载的图像的大小

that what will be the size of the image . so in this code snippet image is resized to 200X200 and center cropped.


Glide.with(this)
        .load("IMAGE URL HERE")
        .placeholder(R.drawable.placeholder)
        .error(R.drawable.imagenotfound)
        .override(200, 200);
        .centerCrop();
        .into(imageView);

享受编码和分享知识

链接:

[http://www.androidtutorialshub.com/glide-image-loading-library-for-android-tutorial/][1]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM