【问题标题】:Image in scrollview doesn't display properly滚动视图中的图像无法正确显示
【发布时间】:2015-11-13 03:55:27
【问题描述】:

我无法在不同的设备上很好地显示图像。 S3 设备的示例,它们显示了我想要的方式:

但是S6设备,图像显示太小,尤其是纵向图像。

任何人都知道如何解决这个问题,因为我尝试使用 weight , match parent 等并没有真正起作用。 p.s.当我将 imageview 放在 scrollview 上方时,有时工作得非常完美。

下面是我当前的 XML

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    >
    <include
        layout="@layout/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />


    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <LinearLayout
            android:padding="10dp"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1">

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:id="@+id/ivEventInfoPoster"
                    android:src="@drawable/carfreeday"
                    android:scaleType="center"
                    android:contentDescription="@string/common_img_desc"
                    />

            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="2"
                android:orientation="vertical">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/tvEventInfoTitle"
                    android:paddingTop="5dp"
                    android:text="Title"
                    android:textSize="24sp"
                    android:textStyle="bold"
                    />
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/tvEventInfoDesc"
                    android:text="Desc"
                    android:layout_marginTop="3dp"
                    android:textSize="16sp"/>
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/tvEventInfoDate"
                    android:text="Date"
                    android:textSize="16sp"
                    android:layout_marginBottom="10dp"/>
            </LinearLayout>
        </LinearLayout>
    </ScrollView>

</LinearLayout>

【问题讨论】:

  • 您是否尝试将android:adjustViewBounds="true" 添加到您的图像视图中?
  • 你有这个适用于不同屏幕尺寸的drawable吗,因为S3的屏幕分辨率是720 x 1280像素,S6是2,560 x 1,440。
  • 是的,这让我的图像有很多空白@NaviRamyle
  • @EricB。但是来自后端的数据因此图像大小是不可预测的。
  • 哦,然后尝试给它一个固定的高度,因为您正在使用 ScrollView 并添加 android:scaleType="fitXY"

标签: android android-xml android-scrollview


【解决方案1】:

用你的ImageView试试这个

<ImageView
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:id="@+id/ivEventInfoPoster"
  android:src="@drawable/carfreeday"
  android:scaleType="fitStart"
  android:adjustViewBounds="true"                 
  android:contentDescription="@string/common_img_desc"
/>

【讨论】:

    【解决方案2】:

    您是否尝试过更新 ImageView 的 scaleType

    除了 scaleType,您还可以设置 ImageView 的 adjustViewBounds 属性

    【讨论】:

      猜你喜欢
      • 2012-10-18
      • 1970-01-01
      • 1970-01-01
      • 2013-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-27
      相关资源
      最近更新 更多