Android 线性布局内部滚动视图不可见

Android 线性布局内部滚动视图不可见,android,android-layout,android-fragments,android-relativelayout,xml-layout,Android,Android Layout,Android Fragments,Android Relativelayout,Xml Layout,当RelativeLayout放在ScrollView中时,我在将片段附加到RelativeLayout时遇到问题。请参阅下面的xml代码- <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:obs="http://schemas.android.com/apk/res-auto"

当RelativeLayout放在ScrollView中时,我在将片段附加到RelativeLayout时遇到问题。请参阅下面的xml代码-

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:obs="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

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

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="48dp" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="10dp"
            android:textColor="#9982d6"
            android:textSize="20sp" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="2dp"
            android:layout_marginTop="10dp"
            android:gravity="center_vertical"
            android:textColor="#9982d6"
            android:textSize="20sp"/>
    </RelativeLayout>

    <View
        android:id="@+id/topDivider2"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#9982d6"
        />

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

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:textColor="#848484"
            android:textSize="14sp" />

        <View
            android:layout_width="match_parent"
            android:layout_height="3.5dp"
            android:layout_alignParentBottom="true"
            android:background="#4ccdd9"
            android:visibility="gone" />

        <View
            android:layout_width="5dp"
            android:layout_height="match_parent"
            android:layout_alignParentRight="true"
            android:layout_marginBottom="4dp"
            android:layout_marginTop="4dp" />
    </RelativeLayout>

    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:dividerHeight="0dp" />

</LinearLayout>

</ScrollView>


在上面的xml代码中,我必须在RelativeLayout GraphContainer中附加一个不起作用的片段。如果我不使用ScrollView,附加片段就可以工作。请帮助…

添加
android:fillViewport
属性以滚动查看。它会起作用的

作为


//======更详细的代码

尝试在覆盖整个活动的布局中使用滚动视图

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


 <ScrollView 
 android:layout_width="wrap_content"
 android:layout_height="wrap_content" >

//other layouts and views here

 </ScrollView>
</RelativeLayout>

//此处有其他布局和视图

如果希望片段可滚动,请从该xml中删除ScrollView并将其放入片段的xml中。我还可以看到您在ScrollView中定义了一个ListView,它不会以这种方式工作,因为ListView有自己的ScrollView

更改线性布局高度以填充父项为什么要指定第一个相对布局高度以匹配父项,在方向垂直的线性布局内部。滚动视图高度应始终为包裹内容,否则这意味着lessit建议使用布局权重滚动视图、线性布局和相对布局的高度都不起作用。我尝试过,但显示错误-未找到属性“fillViewPort”的资源标识符在“android”软件包中,使用android:fillViewport=“true”将端口设置为“P”对于android:fillViewport=“true”和android:layout\u height=“match\u parent”用于滚动视图意味着“将高度设置为父级的高度”。这显然不是使用滚动视图时需要的。毕竟,如果ScrollView的内容总是和它本身一样高,它将变得毫无用处。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="any_bg_color">


 <ScrollView 
 android:layout_width="wrap_content"
 android:layout_height="wrap_content" >

//other layouts and views here

 </ScrollView>
</RelativeLayout>