Android-在坐标布局中滚动和底部图纸

Android-在坐标布局中滚动和底部图纸,android,xml,android-fragments,android-coordinatorlayout,bottom-sheet,Android,Xml,Android Fragments,Android Coordinatorlayout,Bottom Sheet,首先,我不熟悉CoordinatorLayouts,我有一个片段,其中包含几个可滚动的CardView,当我尝试添加底部工作表时,我得到底部工作表必须是coordinatorLayout错误的子项,因此我添加了coordinatorLayout,现在我似乎无法再滚动了 PS:我尝试用NestedScrollView替换ScrollView,但没有效果,我甚至尝试编辑XML标记顺序,但没有解决问题,我仍然无法滚动 是否有一种方法可以使用底页,而无需使用协调布局? 下面是带有ScrollView的X

首先,我不熟悉CoordinatorLayouts,我有一个片段,其中包含几个可滚动的CardView,当我尝试添加底部工作表时,我得到底部工作表必须是coordinatorLayout错误的子项,因此我添加了coordinatorLayout,现在我似乎无法再滚动了

PS:我尝试用
NestedScrollView
替换
ScrollView
,但没有效果,我甚至尝试编辑XML标记顺序,但没有解决问题,我仍然无法滚动

是否有一种方法可以使用
底页
,而无需使用
协调布局

下面是带有ScrollView的XML布局片段:

<android.support.design.widget.CoordinatorLayout
 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="wrap_content"
 tools:context=".ThreeFragment" >
 <ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/MainScrollView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fillViewport="false">
    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/white"
        android:orientation="vertical"
        android:padding="10dp">
        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="1dp"
            style="@style/MyCardViewStyleTitle"
            android:id="@+id/view">
            <TextView
                android:text="I- Pure Vowels"
                android:textStyle="normal"
                android:background="@color/colorPrimaryDark"
                android:textSize="20dp"
                android:textColor="@color/white"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
        </android.support.v7.widget.CardView>
        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_marginBottom="1dp"
            android:layout_height="wrap_content"
            style="@style/MyCardViewStyleContent"
            android:id="@+id/textView10"
            android:layout_below="@+id/view"
            android:layout_alignParentStart="true">
            <TextView
                android:text="Pronouncing : á"
                android:textStyle="bold|italic"
                android:textSize="17dp"
                android:textColor="@color/black"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
            <TextView
                android:text="\n\nas in English father\nE.g.  ár ‘year’"
                android:textStyle="normal"
                android:textSize="40px"
                android:textColor="@color/black"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
        </android.support.v7.widget.CardView>
      <!-- more cardviews -->
    </LinearLayout>
</ScrollView>
 <!-- Bottom Sheet Layout-->
 <include layout="@layout/learn_more_sheet" />
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.CoordinatorLayout
 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="wrap_content"
 tools:context=".ThreeFragment" >
 <android.support.v4.widget.NestedScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/MainScrollView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fillViewport="false">
    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/white"
        android:orientation="vertical"
        android:padding="10dp">
        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="1dp"
            style="@style/MyCardViewStyleTitle"
            android:id="@+id/view">
            <TextView
                android:text="I- Pure Vowels"
                android:textStyle="normal"
                android:background="@color/colorPrimaryDark"
                android:textSize="20dp"
                android:textColor="@color/white"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
        </android.support.v7.widget.CardView>
        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_marginBottom="1dp"
            android:layout_height="wrap_content"
            style="@style/MyCardViewStyleContent"
            android:id="@+id/textView10"
            android:layout_below="@+id/view"
            android:layout_alignParentStart="true">
            <TextView
                android:text="Pronouncing : á"
                android:textStyle="bold|italic"
                android:textSize="17dp"
                android:textColor="@color/black"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
            <TextView
                android:text="\n\nas in English father\nE.g.  ár ‘year’"
                android:textStyle="normal"
                android:textSize="40px"
                android:textColor="@color/black"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
        </android.support.v7.widget.CardView>
      <!-- more cardviews -->
    </LinearLayout>
</android.support.v4.widget.NestedScrollView>
 <!-- Bottom Sheet Layout-->
 <include layout="@layout/learn_more_sheet" />
</android.support.design.widget.CoordinatorLayout>

这是带有NestedScrollView的XML布局片段:

<android.support.design.widget.CoordinatorLayout
 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="wrap_content"
 tools:context=".ThreeFragment" >
 <ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/MainScrollView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fillViewport="false">
    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/white"
        android:orientation="vertical"
        android:padding="10dp">
        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="1dp"
            style="@style/MyCardViewStyleTitle"
            android:id="@+id/view">
            <TextView
                android:text="I- Pure Vowels"
                android:textStyle="normal"
                android:background="@color/colorPrimaryDark"
                android:textSize="20dp"
                android:textColor="@color/white"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
        </android.support.v7.widget.CardView>
        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_marginBottom="1dp"
            android:layout_height="wrap_content"
            style="@style/MyCardViewStyleContent"
            android:id="@+id/textView10"
            android:layout_below="@+id/view"
            android:layout_alignParentStart="true">
            <TextView
                android:text="Pronouncing : á"
                android:textStyle="bold|italic"
                android:textSize="17dp"
                android:textColor="@color/black"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
            <TextView
                android:text="\n\nas in English father\nE.g.  ár ‘year’"
                android:textStyle="normal"
                android:textSize="40px"
                android:textColor="@color/black"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
        </android.support.v7.widget.CardView>
      <!-- more cardviews -->
    </LinearLayout>
</ScrollView>
 <!-- Bottom Sheet Layout-->
 <include layout="@layout/learn_more_sheet" />
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.CoordinatorLayout
 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="wrap_content"
 tools:context=".ThreeFragment" >
 <android.support.v4.widget.NestedScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/MainScrollView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fillViewport="false">
    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/white"
        android:orientation="vertical"
        android:padding="10dp">
        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="1dp"
            style="@style/MyCardViewStyleTitle"
            android:id="@+id/view">
            <TextView
                android:text="I- Pure Vowels"
                android:textStyle="normal"
                android:background="@color/colorPrimaryDark"
                android:textSize="20dp"
                android:textColor="@color/white"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
        </android.support.v7.widget.CardView>
        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_marginBottom="1dp"
            android:layout_height="wrap_content"
            style="@style/MyCardViewStyleContent"
            android:id="@+id/textView10"
            android:layout_below="@+id/view"
            android:layout_alignParentStart="true">
            <TextView
                android:text="Pronouncing : á"
                android:textStyle="bold|italic"
                android:textSize="17dp"
                android:textColor="@color/black"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
            <TextView
                android:text="\n\nas in English father\nE.g.  ár ‘year’"
                android:textStyle="normal"
                android:textSize="40px"
                android:textColor="@color/black"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
        </android.support.v7.widget.CardView>
      <!-- more cardviews -->
    </LinearLayout>
</android.support.v4.widget.NestedScrollView>
 <!-- Bottom Sheet Layout-->
 <include layout="@layout/learn_more_sheet" />
</android.support.design.widget.CoordinatorLayout>

主要活动XML布局

<android.support.design.widget.CoordinatorLayout
  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"
  xmlns:tools="http://schemas.android.com/tools"
  tools:context="com.incorp.anisvikernes.englishtonorse.MainActivity">
>

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="160px"
            app:tabMode="fixed"
            app:tabGravity="fill"/>
    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"  />
</android.support.design.widget.CoordinatorLayout>

>

编辑:从片段中删除BottomSheetLayout,并将其放入ViewPager下的活动中。然后在片段顶部放置一个
NestedScrollView
,属性如下:

<android.support.v4.widget.NestedScrollView 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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:fillViewport="true">
var sheet = (View)getActivity().findViewById(R.id.{sheet});
sheet.setVisbility(view.Visible);
然后,在您拥有的其他片段中,使用
sheet.setvisibility(view.Gone)执行相同的操作

要在按下back时隐藏它,请在活动中使用此按钮:

 @Override
public void onBackPressed() {

       if (sheet.getVisibility() == View.VISIBLE) {
    sheet.setVisbility(view.Gone);

    }

1.将android.support.v4.widget.NestedScrollViewScrollView更改为android.support.v4.widget.NestedScrollView。2.您希望每张卡都能单独滚动,还是希望整个视图都能滚动?第一步,对不起,它已经是android.support.v4.widget.NestedScrollView了,我希望整个视图都是scrollable@Sígvardr您发布的代码有一个输入错误:android.support.v4.widget.nestedScrollViewScrollView您的意思是它应该是这样的:
是。但是试着用第二个和不用第二个。并将app:layout\u behavior=“@string/appbar\u scrolling\u view\u behavior”添加到两者。