ImageView的,不进行缩放
问题描述:
我有一个ListView,显示行ImageView的,不进行缩放
这是XML:
...
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="@color/white"
android:orientation="vertical" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".30">
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@drawable/face"
android:scaleType="centerCrop" />
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".70"
android:background="@color/white"
android:padding="4dp" >
// Other views...
</LinearLayout>
</LinearLayout>
…
,并得到这样的结果:
这是原始图像
需要的是没有缩放图像,就像这样:
我使用的Android版本:ScaleType = “centerCrop” 我与Android测试:adjustViewBounds = “true” 和许多其他的参数,但从未成功
想法?
在此先感谢
答
设置你的图像android:src
而不是android:background
才会工作。
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/face"
android:scaleType="centerCrop" />
所有视图可以采取的背景图像
的src
到ImageView
具有附加的特征:
- 不同scaling types
-
adjustViewBounds
用于设置边界以匹配图像尺寸 - 一些转换如alpha-setting
而更多的,你可以在the docs找到。
答
变化android:background="@drawable/face"
到android:src="@drawable/face"
规模类型android:src
答
您可以使用android:src
代替android:background
设置你的绘制。例如:
<ImageView android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/face"
android:scaleType="centerCrop" />
此外,为什么不使用像Photoshop这样的图像编辑软件裁剪图像,而是使用该图像呢?应避免动态缩放和操纵图像,以尽可能避免大量使用系统资源。
答
我觉得,你的问题是插入的LinearLayout和FrameLayout里的权重。请使用RelativeLayout而不用重量。系统无法裁剪您的照片,因为系统无法测量ImageView,无法将其与照片进行比较。总之系统认为“这是图像和ImageView相等”。 我已经这样做了:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp">
<ImageView
android:id="@+id/image"
android:layout_height="50dp"
android:layout_width="match_parent"
android:src="@drawable/photo"
android:scaleType="centerCrop"
android:contentDescription="@string/app_name"
android:layout_alignParentTop="true"
/>
<TextView android:layout_height="150dp"
android:layout_width="match_parent"
android:text="@string/text"
android:layout_below="@id/image"
android:maxLength="350"
android:layout_marginTop="5dp"/>
</RelativeLayout>