布局将视图推向屏幕

时间:2016-04-25 01:28:28

标签: android android-layout android-imageview textview android-framelayout

所以,我在FrameLayout中有一个ImageView。我这样需要它。我觉得这里的问题是图像和它的大小本身。图像的布局进一步向下推动屏幕上的所有其他视图,留下了应该来自布局的相当大的空白空间。

我发现硬编码高度值让我最小化了这个问题。如果高度为wrap_content,则图像将达到相同的点,但应该来自布局的空白区域延伸到极端长度。

所以我想知道这是一个图像大小(或分辨率?)问题(似乎是)或其他任何问题,以及是否有比硬编码布局高度更好的解决方案。提前谢谢。

以下是代码:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="700dp">

        <ImageView
            android:id="@+id/image_header"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scaleType="fitStart"
            android:src="@drawable/me_and_gundam" />

        <View
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/gradient" />
    </FrameLayout>


    <TextView
        android:fitsSystemWindows="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="16dp"
        android:text="My Nanodegree Apps!"
        android:textAlignment="center"
        android:textSize="24sp" />

这就是它的样子:

enter image description here

1 个答案:

答案 0 :(得分:2)

您是否尝试将框架布局高度设置为wrap_content,对我来说很好

    <ImageView
        android:id="@+id/image_header"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scaleType="fitStart"
        android:src="@drawable/me_and_gundam" />

    <View
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/gradient" />
</FrameLayout>