LinearLayout的最大高度是多少?

时间:2013-10-03 16:45:03

标签: android layout android-linearlayout

我有一个垂直线性布局,不会超出一定的限制。

这是imageview中包含centerCrop的布局 http://tinypic.com/r/20nm6s/5

这是没有裁剪设置的布局(所以它应该是全宽和巨大的) http://tinypic.com/r/vzk7kw/5

所以我的想法是,我的布局中没有看到一些隐含的最大高度,但我看不到它的位置,你能发现我的错误吗?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            >
    <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:background="@drawable/dropshadow"
            >
        <TextView
                android:id="@+id/heading"
                android:layout_gravity="center"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                />
        <ImageView
            android:id="@+id/featuredimage"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:adjustViewBounds="true"
            android:maxHeight="1000dp"
            android:scaleType="centerCrop"
            android:layout_marginTop="10dp"
            android:layout_marginBottom="10dp"
            />
    </LinearLayout>
</RelativeLayout>

1 个答案:

答案 0 :(得分:2)

布局的“隐式”最大高度是其父级的高度。由于您在两个布局上都使用wrap_content,这意味着父级有效屏幕区域,减去您正在使用的其他任何视图(例如TextView)。除非您将它放在滚动容器中,例如ScrollView,否则它不会超过屏幕大小。

删除裁剪时,ImageView未显示“全宽和大”的原因是因为scaleType的默认ImageViewfitCenter。此特定视图受布局的宽度限制,因此在保持纵横比的同时缩小图像。