Android - 显示图像以适应设备的宽度

时间:2016-06-29 09:12:06

标签: android android-imageview

我正在开发一个Android应用程序,以便在列表视图中显示一些照片。 这是listview中每个项目的布局。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <ImageView
        android:id="@+id/exam_page_item_imageview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scaleType="centerCrop"/>
</RelativeLayout>

我的列表视图显示

enter image description here

我想显示适合设备宽度的imageview。 (仅适合宽度)

enter image description here

你能给我一些建议或有任何想法解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

试试这个:

<ImageView
android:id="@id/imgview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitCenter" />


android:adjustViewBounds = "true"

当您的图片大于imageview时,它会有所帮助。它不会拉伸图像,但会缩小图像。

android:scaleType="fitCenter"

当您的图像小于imageview时,它会将图像拉伸到其父图像的宽度。

相关问题