【发布时间】:2017-01-23 16:39:28
【问题描述】:
这个布局有两个问题:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="130dp"
android:orientation="horizontal"
android:background="@null">
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:src="@drawable/image1"
android:id="@+id/image1"
android:scaleType="centerCrop"
android:background="@drawable/card_background"
android:layout_weight=".5"
/>
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:src="@drawable/image2"
android:id="@+id/image2"
android:scaleType="centerCrop"
android:background="@drawable/card_background"
android:layout_weight=".5"
/>
</LinearLayout>
当我在 ImageViews 中放置不同的图像时,发生了这种情况:
- ImageViews 高度大于 130dp 但是我把高度设置为 (match_parent) 并且父高度是 130dp 。
- ImageViews 的宽度不一样,但两个 ImageViews 的权重相同,但较大的一个比另一个占用更多的宽度。
【问题讨论】:
-
你没有给父布局一个 weight_sum
-
我做了,还是一样
-
你的意思是图片的大小不一样,或者那些视图的大小不一样?您可以在 imageViews 中使用
scaletype=fitxy使图像适合其边界 -
显示输出图像以澄清
-
@Omer 为 true,但您可以使用
android:adjustViewBounds=true
标签: android android-layout imageview android-linearlayout