我有一個XML頁面有一個TabLayout和RecyclerView這些元素應該向下滾動頁面,他們這樣做,但我有一個ViewPager和其他TextView也滾動的元素,我也不想要它們。我希望這些元素保持不變。例如,當我向下滾動recyclerview時,ViewPager應該消失,而不是向下滾動頁面。這是我不想滾動Android我怎樣才能讓我的XML中的項目保持在固定的位置
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/TextView_TrendingArtist"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:text="Trending Artists"
android:textColor="@color/white"
android:textSize="16sp" />
<android.support.v4.view.ViewPager
android:id="@+id/trending_pager_list"
android:layout_width="match_parent"
android:layout_height="200dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:id="@+id/TextView_Artist"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:text="All Artists"
android:textColor="@color/white"
android:textSize="16sp" />
</LinearLayout>
再次爲我向下滾動說的LinearLayout,一切都在它應該是不可見的頁面的代碼。這是我的完整的XML代碼
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data class=".ArtistListBinding">
<variable
name="toolbarHandler"
type="com.mgrmobi.joox.interfaces.ToolbarClickListener" />
<variable
name="eventsAdapter"
type="com.mgrmobi.joox.adapters.ArtistListAdapter" />
<import type="android.view.View" />
</data>
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background_color">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/toolbar_color"
android:contentInsetLeft="0dp"
android:contentInsetRight="0dp"
android:elevation="8dp"
app:contentInsetLeft="0dp"
app:contentInsetRight="0dp"
app:elevation="8dp">
<ImageView
android:id="@+id/menu"
android:layout_width="32dp"
android:layout_height="48dp"
android:onClick="@{ toolbarHandler.onMenuButtonTapped }"
android:scaleType="center"
android:src="@drawable/menu" />
<TextView
android:id="@+id/title"
style="@style/toolbarTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/artist_list_title" />
</android.support.v7.widget.Toolbar>
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/trending_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="8dp"
android:background="@color/toolbar_color"
android:elevation="8dp"
android:scrollbars="horizontal"
app:elevation="8dp"
app:layout_scrollFlags="scroll|enterAlways"
app:tabIndicatorColor="#29b6f6"
app:tabSelectedTextColor="#FFF"
app:tabTextColor="#B2FFFFFF" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/artist_list"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/TextView_TrendingArtist"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:text="Trending Artists"
android:textColor="@color/white"
android:textSize="16sp" />
<android.support.v4.view.ViewPager
android:id="@+id/trending_pager_list"
android:layout_width="match_parent"
android:layout_height="200dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:id="@+id/TextView_Artist"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:text="All Artists"
android:textColor="@color/white"
android:textSize="16sp" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/artist_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:listItem="@layout/artist_card" />
<ProgressBar
android:id="@+id/paging_progress"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="center_horizontal"
android:visibility="gone" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="@string/no_artists_text"
android:textColor="@color/white"
android:textSize="18sp"
android:visibility="@{ eventsAdapter.itemCount == 0 ? View.GONE : View.VISIBLE }" />
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/progress"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#82000000"
android:gravity="center"
tools:visibility="gone">
<ProgressBar
android:layout_width="48dp"
android:layout_height="48dp" />
</LinearLayout>
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:clickable="false" />
</RelativeLayout>
<include layout="@layout/music_controller" />
</LinearLayout>
<FrameLayout
android:id="@+id/drawer_container"
android:layout_width="@dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#FFF" />
</android.support.v4.widget.DrawerLayout>
</layout>
的問題是,RecyclerView也是ViewPager內部發生像這樣的
,你可以從圖片看出,ViewPager部分封閉RecyclerView一旦向上滾動。