滚动视图不适用于帧布局

时间:2018-07-17 06:21:08

标签: android

我有一个活动布局,其中包括我的片段容器,

<include
    layout="@layout/content_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/background_container" />

我的片段容器由linearlayout和framelayout组成

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:background="@android:color/transparent"
   android:padding="10dp">

   <FrameLayout
     android:id="@+id/fragment_container"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:background="@android:color/transparent" />

</LinearLayout>

问题是我必须在此容器中添加可滚动片段,但滚动似乎无法正常工作。我的布局是这样的

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

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

         ...

         ...

    </LinearLayout>
</ScrollView>

我尝试了几个类似的答案

  1. 使用NestedScrollView
  2. 为框架布局添加最小高度
  3. 使用fillViewport =“ true”

但是似乎没有任何效果。知道我做错了什么吗?任何帮助,将不胜感激。提前致谢!干杯!

编辑:

我的活动布局包含导航抽屉,我不知道这是否重要。我使用添加视图

ft.replace(R.id.fragment_container, myFragment).commit();

我也不知道片段是否会取代我的观点。请帮忙。谢谢

1 个答案:

答案 0 :(得分:2)

似乎我的片段容器的LinearLayout缺少方向,也缺少frameLayout android:layout_height应该是match_parent

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:background="@android:color/transparent"
   android:orientation="vertical"  // orientation
  android:padding="10dp">

    <FrameLayout
         android:id="@+id/fragment_container"
         android:layout_width="match_parent"
         android:layout_height="match_parent" // match_parent
         android:background="@android:color/transparent" />

</LinearLayout>
相关问题