ImageView的图像未使用LinearLayout的高度进行调整

时间:2014-03-19 18:30:08

标签: android android-layout android-linearlayout android-imageview

第一次问一个问题,所以请温柔。 :)

我试图在ImageView内创建LinearLayout s的嵌套版式。父LinearLayout需要匹配根视图的宽度,但其高度由其保存的2 ImageView个组件决定。

2个ImageView分量需要对LinearLayout父级内的宽度(即50%)进行相等加权,并保持其比例高度。

然而,虽然ImageView s的宽度正确计算且图像本身的高度正确,但父LinearLayout的高度不正确。

下面是我正在使用的XML代码,道歉但我目前没有足够的声誉点来发布图片,这可能会让这很困难。

XML代码

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/grey"
    android:orientation="vertical"
    android:padding="10dp" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="5dp"
        android:background="@drawable/container_dropshadow"
        android:orientation="horizontal"
        android:padding="5dp"
        android:weightSum="2" >

        <ImageView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="horizontal"
            android:padding="5dp"
            android:src="@drawable/barcode" />

        <ImageView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="horizontal"
            android:padding="5dp"
            android:src="@drawable/barcode" />
    </LinearLayout>

</LinearLayout>

这就是我的目标

enter image description here

任何帮助都会非常感激,对任何礼仪失败表示道歉,

丹尼

1 个答案:

答案 0 :(得分:1)

您应为每个ImageView添加以下行:

android:adjustViewBounds="true"

有关 xml 属性的详细信息,请参阅here

相关问题