RelativeLayout中的ScrollView不起作用

时间:2016-04-02 09:19:12

标签: android android-relativelayout

我有一个LinearLayout并在其中动态创建元素。如果它的高度大于屏幕高度的0.8,我需要使它可滚动。我试着这样做。我的错误在哪里?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent" android:layout_height="match_parent"
        android:id="@+id/layoutContainer" android:orientation="vertical"
        android:baselineAligned="false" android:weightSum="1">


            <ScrollView
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:scrollbars="vertical"
                android:layout_weight="0.85" >
            <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent" android:layout_height="wrap_content"
                android:id="@+id/alarmsLayout" android:orientation="vertical"
                android:layout_marginTop="70dp" >
            </LinearLayout>
            </ScrollView>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="0.15">
            <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/addAlarmBtn"
                android:src="@drawable/time"
                android:layout_marginBottom="15dp" />
        </LinearLayout>
    </LinearLayout>

3 个答案:

答案 0 :(得分:1)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layoutContainer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:weightSum="1"
    android:baselineAligned="false"
    android:orientation="vertical" >


        <ScrollView
            android:layout_weight="0.8" 
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:scrollbars="vertical" >

            <LinearLayout
                android:id="@+id/alarmsLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="70dp"
                android:orientation="vertical" >
            </LinearLayout>
        </ScrollView>


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.15" >

        <ImageView
            android:id="@+id/addAlarmBtn"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentBottom="true"
            android:layout_marginBottom="15dp"
            android:src="@drawable/background_button" />
    </RelativeLayout>

</LinearLayout>

答案 1 :(得分:0)

    <RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width"match_parent"
    android:layout_height="match_parent">

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scrollbars="vertical" >

            <LinearLayout 
            android:layout_width="match_parent" 
            android:layout_height="wrap_content"
            android:id="@+id/alarmsLayout" android:orientation="vertical"
            android:layout_marginTop="70dp" >
            </LinearLayout>

        </ScrollView>

    <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_marginBottom="15dp">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/addAlarmBtn"
            android:src="@drawable/time" />
    </RelativeLayout>

</RelativeLayout>

答案 2 :(得分:0)

尝试使用此

<?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="match_parent"
    android:orientation="vertical">
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width ="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.8">

<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/alarmsLayout" android:orientation="vertical"
    android:layout_marginTop="70dp" >
</LinearLayout>

</ScrollView>
</RelativeLayout>
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_marginBottom="15dp"
    android:layout_height="0dp"
    android:layout_weight="0.2"
    android:gravity="center">

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/addAlarmBtn"
    android:src="@drawable/badge" />
</RelativeLayout>

    </LinearLayout>