gar*_*tor 41 android android-layout android-imageview android-relativelayout
我有一个方形图像(虽然这个问题也适用于矩形图像).我想尽可能大地显示图像,必要时拉伸它们以填充它们的父母,同时仍然保持纵横比.图像小于ImageView.问题是,我无法拉伸图像并"匹配"ImageView的高度和宽度.
这是我的XML布局文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp">
<ImageView android:id="@+id/image"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:layout_marginTop="10dp"/>
<TextView android:id="@+id/name"
android:layout_below="@id/image"
android:layout_alignLeft="@id/image"
android:layout_marginTop="20dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="18dp"/>
<TextView android:id="@+id/name2"
android:layout_below="@id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="14dp"/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
我已经使用的多种组合fill_parent,wrap_content与多个scaleTypes: ,fitCenter,fitStart,fitEnd,centerInside他们都画在正确的纵横比的图像,但没有人真正缩放图像UP和ImageView的本身,导致无论是在TextViews被推所有屏幕下方,ImageView内部空白区域,图像未缩放或图像裁剪.
我无法为此找到合适的组合.
Foa*_*Guy 103
这些:
android:layout_height="wrap_content"
android:scaleType="fitStart"
android:adjustViewBounds="true"
Run Code Online (Sandbox Code Playgroud)
应调整图像大小并更改边界的大小以适合新的图像大小.如果在您的设备上没有这样做,请发布您正在使用的图像以及您正在测试的设备.
Con*_*ext 46
使用此代码:
android:scaleType="fitXY"
有关图像缩放的详细信息,看看这是什么文章中示意这里
摘要:
center将图像置于视图中心,但不执行缩放

centerCrop均匀缩放图像(保持图像的纵横比),使图像的尺寸(宽度和高度)等于或大于视图的相应尺寸(减去填充).然后图像在视图中居中

centerInside均匀缩放图像(保持图像的纵横比),使图像的尺寸(宽度和高度)等于或小于视图的相应尺寸(减去填充)

fitCenter
fitEnd
fitStart
fitXY
matrix绘图时使用图像矩阵缩放

这里有更多细节新文章
Feb*_*hew 14
这个xml代码将起作用!如果您指定应用程序宽度始终与窗口相同,android:adjustViewBounds="true"则将设置高度与图像的比例相对应.
<ImageView
android:adjustViewBounds="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/screen"/>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
56811 次 |
| 最近记录: |