Android:修复空白的scrollview布局?

时间:2018-11-11 02:29:26

标签: android android-linearlayout android-scrollview android-relativelayout

我的目标是在视图顶部显示一个工具栏,然后是一个TextView,然后是一个ScrollView部分,然后是一个始终显示在视图底部的页脚。下面仅显示工具栏和TextView标头。 ScrollView部分或底部的页脚未显示任何内容。我在这里想念什么?

EditActivity.xml

<RelativeLayout

    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFFFFF"
    android:focusableInTouchMode="true"
    tools:context=".EditActivity">

    <include
        android:id="@+id/toolbar"
        layout="@layout/toolbar" >
    </include>

<RelativeLayout android:id="@+id/header"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:layout_below="@+id/toolbar"  >

    <TextView
    android:id="@+id/create_skycard"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textStyle="bold"
    android:textColor="@color/colorFlLabelFinal"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:clickable="false"  />

</RelativeLayout>

<RelativeLayout android:id="@+id/myFooter"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"  >

    <ViewFlipper
        android:id="@+id/viewFlipper1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="5dp"  >

        <include layout="@layout/cardview_nobuttons"
            android:id="@+id/cardviewNobuttons"  />

        <include layout="@layout/cardview_previewbuttons"
            android:id="@+id/cardviewPreviewbuttons" />            

    </ViewFlipper>

</RelativeLayout>  

<ScrollView
android:id="@+id/ScrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/header"
android:layout_above="@+id/myFooter"
android:fillViewport="true"  >

<LinearLayout
    android:id="@+id/LinearLayout1"
    style="@style/scrollbar_shape_style"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"  >      

    <com.wimso.v108.widget.EditText
    ...  />

</LinearLayout>

</ScrollView>

</RelativeLayout>

1 个答案:

答案 0 :(得分:1)

首先,应限制页脚视图的高度。我将ViewFlipper的高度设置为128dp进行测试,因此您可以根据其内容计算自己的高度。

第二:您应该为android:layout_alignParentTop="true"设置include,其ID为toolbar。为此,您应该像我一样设置高度和重量。

第三:ScrollView的高度应为wrap_content,而不是match_parent,以确保其在页眉和页脚视图之间延伸。

在进行上述更正之后,这是您的布局源代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFFFFF"
    android:focusableInTouchMode="true"
    tools:context=".EditActivity">

    <include
        android:id="@+id/toolbar"
        layout="@layout/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true" />

    <RelativeLayout
        android:id="@+id/header"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/toolbar"
        android:gravity="center_horizontal">

        <TextView
            android:id="@+id/create_skycard"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:clickable="false"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textColor="@color/colorFlLabelFinal"
            android:textStyle="bold" />

    </RelativeLayout>

    <ScrollView
        android:id="@+id/ScrollView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/myFooter"
        android:layout_below="@+id/header"
        android:fillViewport="true">

        <LinearLayout
            android:id="@+id/LinearLayout1"
            style="@style/scrollbar_shape_style"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <com.wimso.v108.widget.EditText
            ... />

        </LinearLayout>

    </ScrollView>

    <RelativeLayout
        android:id="@+id/myFooter"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true">

        <ViewFlipper
            android:id="@+id/viewFlipper1"
            android:layout_width="match_parent"
            android:layout_height="128dp"
            android:layout_marginBottom="5dp">

            <include
                android:id="@+id/cardviewNobuttons"
                layout="@layout/cardview_nobuttons" />

            <include
                android:id="@+id/cardviewPreviewbuttons"
                layout="@layout/cardview_previewbuttons" />

        </ViewFlipper>

    </RelativeLayout>

</RelativeLayout>