Android Imageview填充屏幕宽度

tsi*_*sil 19 android android-layout android-view

这是我的布局文件:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="#000"
tools:context=".CproductDetails" >

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/shape_bg"
        >

        <ImageView
            android:id="@+id/product_image"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_tweet_placeholder_photo_dark_error"
            android:scaleType="center" />

        <TextView
            android:id="@+id/product_name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textIsSelectable="true"
            android:textColor="#95ab56"
            android:textSize="20sp"
            android:layout_marginTop="7dip" />

        <TextView
            android:id="@+id/product_price"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textIsSelectable="true"
            android:textSize="20sp"
            android:textColor="#efeeea" />

        <TextView
            android:id="@+id/product_commerce"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textIsSelectable="true"
            android:textSize="20sp" />

        <TextView
            android:id="@+id/product_city"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textIsSelectable="true"
            android:textSize="15sp"
            android:layout_marginTop="10dip"
            android:layout_marginBottom="10dip" />

        <TextView
            android:id="@+id/product_township"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textIsSelectable="true"
            android:textSize="15sp"
            android:visibility="gone"
            android:layout_marginBottom="10dip"
            android:drawableLeft="@drawable/location_place"
            android:drawablePadding="7dip" />

        <TextView
            android:id="@+id/product_website"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textIsSelectable="true"
            android:autoLink="web"
            android:textSize="15sp"
            android:drawableLeft="@drawable/location_web_site"
            android:drawablePadding="7dip"
            android:visibility="gone" />

         <TextView
            android:id="@+id/product_tel"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textIsSelectable="true"
            android:textSize="20sp"
            android:drawableLeft="@drawable/device_access_call"
            android:drawablePadding="7dip"
            android:visibility="gone" />

    </LinearLayout>
Run Code Online (Sandbox Code Playgroud)

手机的结果:

在此输入图像描述

和7in平板电脑的结果:

在此输入图像描述

我想让图像也以平板电脑填充屏幕宽度.像Twitter应用程序一样:

在此输入图像描述

在此输入图像描述

Sim*_*mon 57

听起来就像你想要使用android:scaleType="fitCenter"android:adjustViewBounds="true"在你的ImageView上.


tsi*_*sil 9

谢谢你,但你的答案都没有解决我的问题.最后我使用了Maurycy Wojtowicz的ScaleImageView类.

此视图将通过确定是否设置高度或宽度来自动确定宽度或高度,并根据图像尺寸缩放其他尺寸

  • 该类手动向图像添加 centerInside 或 centerCrop 缩放。这是关于这个问题和这个问题的 10 个副本的许多更好答案的臃肿版本,不需要额外的课程。 (2认同)

sti*_*ike 6

android:scaleType="fitXY".

这将独立地缩放X和Y中的图像,以便src完全匹配dst.这可能会改变src的宽高比.

  • 这对于大多数照片来说相对无用,因为宽高比是至关重要的 (3认同)