【问题标题】:List View row height is not varying列表视图行高不变
【发布时间】:2013-11-25 10:37:40
【问题描述】:

我有以下布局,每行似乎有不同的高度,这取决于一个图像是否得到解决。布局定义如下。无需对 layout_height 进行硬编码。我怎样才能确保所有人都适合相同的高度。我知道图像分辨率起着重要作用。所以,它可能不可行。不过,我正在寻找一种创造性的方法来解决这个问题。

第一张图片是我的默认头像(它是 50x50 .png 文件)。如果有一行的附加图像,它将以 50x50 .jpeg 的形式出现。因此,不同的文件类型和不同的分辨率。

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_vertical"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/imgOwner"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="0.75"
        android:layout_marginRight="10dp"
        android:scaleType="centerInside"
        android:contentDescription="Image Owner"
        android:src="@drawable/icon_default_avator" />

    <TextView
        android:id="@+id/txtUserName"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="10"
        android:text="User Name"
        android:textSize="10sp" />
</LinearLayout>

<TextView
    android:id="@+id/txtVideoTitle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Video Title"
    android:layout_marginBottom="10dip"
    android:textSize="10sp" />

<TextView
    android:id="@+id/txtVideoName"
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:textSize="10sp"
    android:text="Video Information"
    android:layout_marginBottom="10dip"
    />

【问题讨论】:

  • 你试过android:scaleType="fitXY"ImageView吗?
  • 是的,我做到了。看起来不太对。

标签: android listview height row


【解决方案1】:

试试这个方法

像这样设置 imageview 属性

<ImageView
        android:id="@+id/imgOwner"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_marginRight="10dp"
        android:adjustViewBounds="true"
        android:contentDescription="Image Owner"
        android:src="@drawable/ic_launcher" />

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多