2016-11-08 66 views
0

嗨,我想使視圖不能滾動recyclerview,例如以上textlay回滾視圖nestedscrollview,如何使textview不滾動,而回收滾動像往常一樣如何使查看recyclerview永久示例不滾動嵌套scrollview

我的代碼

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.NestedScrollView 
    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:keepScreenOn="true" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    android:fillViewport="true" > 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center_horizontal" 
     android:focusableInTouchMode="true" 
     android:paddingBottom="@dimen/activity_vertical_margin" 
     android:paddingLeft="@dimen/activity_horizontal_margin" 
     android:paddingRight="@dimen/activity_horizontal_margin" 
     android:paddingTop="@dimen/activity_vertical_margin" > 

     <TextView 
      android:id="@+id/textView" 
      android:textColor="#43a047" 
      android:typeface="serif" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentTop="true" 
      android:text="@string/app" 
      android:gravity="center" 
      android:textStyle="bold" 
      android:textSize="15sp" /> 

     <android.support.v7.widget.RecyclerView 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/recyclerview" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/textView" 
      android:layout_marginTop="5dp" 
      android:divider="@color/colorAccent" 
      android:dividerHeight="1dp" /> 

</RelativeLayout> 

</android.support.v4.widget.NestedScrollView> 

如何讓TextView中不會滾動

+0

爲什麼你不得不在這裏使用嵌套的滾動視圖? –

+0

然後工具欄不會滾動應用程序:layout_behavior =「@ string/appbar_scrolling_view_behavior」,即使將它放在相對視圖中,這也是爲什麼 – AndroidBeginnerJhon

+0

可以發佈圖像以顯示您想要的內容嗎? –

回答

0

你有NestedScrollViewTextView。因此,您的TextView因該父視圖而滾動。類似的東西會工作:

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

    <TextView 
     android:id="@+id/textView" 
     android:textColor="#43a047" 
     android:typeface="serif" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:text="@string/app" 
     android:gravity="center" 
     android:textStyle="bold" 
     android:textSize="15sp" /> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/recyclerview" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/textView" 
     android:layout_marginTop="5dp" 
     android:divider="@color/colorAccent" 
     android:dividerHeight="1dp" /> 
</RelativeLayout> 
+0

然後工具欄不滾動應用程序:layout_behavior =「@字符串/ appbar_scrolling_view_behavior」,即使把它放在相對的視圖 – AndroidBeginnerJhon

+0

我真的不能明白你想要做什麼。請張貼圖片或其他東西。 –

0

RecyclerView自身滾動的,所以只是刪除NestedScrollView

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:gravity="center_horizontal" 
    android:focusableInTouchMode="true" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" > 

    <TextView 
     android:id="@+id/textView" 
     android:textColor="#43a047" 
     android:typeface="serif" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:text="@string/app" 
     android:gravity="center" 
     android:textStyle="bold" 
     android:textSize="15sp" /> 

    <android.support.v7.widget.RecyclerView 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/recyclerview" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/textView" 
     android:layout_marginTop="5dp" 
     android:divider="@color/colorAccent" 
     android:dividerHeight="1dp" /> 

+0

那麼工具欄不會滾動app:layout_behavior =「@string/appbar_scrolling_view_behavior」,即使將它放在相對視圖中 – AndroidBeginnerJhon