即使在景观模式下,我也想维护图像视图的纵横比。即使我使用scaleType:fitxy和awtionBounds,也是我的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>
这是无关的,但是如果您不希望在androidmanifest.xml文件中所有设置的景观模式为活动android:screenOrientation="portrait"
,则可以提供帮助,因为您不输入景观模式
使用percorperframeLayout https://developer.android.com/reference/android/android/support/percent/percent/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>
我认为,当您不确定服务器的尺寸时,这将解决您的问题。
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]