2017-11-18 113 views
0

我想在滾動視圖分頁器時摺疊我的標題視圖。 在下面的圖像relativelayout3是我試圖尋找我要崩潰的佈局..向上滾動viewpager時摺疊標題視圖

example

喜歡的東西在應用頁面Play商店中的預覽圖像崩潰..

和relativelayout3以下行,但它沒有工作

app:layout_scrollFlags="scroll|enterAlways" 

這我完整的XML,

<?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" 
    xmlns:app="http://schemas.android.com/apk/res-auto"> 
    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 
      <RelativeLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:id="@+id/relativeLayout3" 
       app:layout_scrollFlags="scroll|enterAlways" 
       > 
    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="55dp" 
     android:id="@+id/toolbar" 
     android:background="@color/cornflower_blue_two" 
     android:elevation="5dp"> 

     <ImageButton 
      android:id="@+id/more" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentEnd="true" 
      android:layout_centerVertical="true" 
      android:layout_marginEnd="10dp" 
      android:background="@null" 
      android:src="@drawable/ic_dots_vertical" /> 

     <ImageButton 
      android:id="@+id/back" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentStart="true" 
      android:layout_centerVertical="true" 
      android:layout_marginEnd="5dp" 
      android:layout_marginStart="10dp" 
      android:background="@null" 
      android:src="@drawable/ic_arrow_left" /> 

    </RelativeLayout> 
    <ss.com.bannerslider.views.BannerSlider 
     android:id="@+id/slider" 
     android:layout_width="match_parent" 
     android:layout_height="250dp" 
     android:background="@color/blue" 
     android:layout_below="@id/toolbar" 
     /> 
      </RelativeLayout> 

      <RelativeLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_alignParentStart="true" 
       android:layout_below="@+id/relativeLayout3"> 

       <TextView 
        android:id="@+id/product" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_margin="10dp" 
        android:text="Blah Blah" 
        android:textColor="@color/dark_gray" 
        android:textSize="25sp" 
        android:textStyle="bold" /> 

       <TextView 
        android:id="@+id/brand" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignStart="@+id/product" 
        android:layout_below="@+id/product" 
        android:text="Blah inc." 
        android:textSize="20sp" 
        android:textStyle="bold" /> 

       <TextView 
        android:id="@+id/ratings" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignBaseline="@+id/brand" 
        android:layout_alignBottom="@+id/brand" 
        android:layout_marginStart="10dp" 
        android:layout_toEndOf="@+id/brand" 
        android:background="@color/ratings" 
        android:paddingEnd="10dp" 
        android:paddingStart="10dp" 
        android:text="4.7" 
        android:textColor="@color/white" 
        android:textSize="20sp" 
        android:textStyle="bold" /> 

       <android.support.design.widget.TabLayout 
        android:id="@+id/tabLayout" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_alignParentStart="true" 
        android:layout_below="@+id/brand" 
        android:layout_marginTop="14dp" 
        app:tabGravity="fill" 
        app:tabMode="fixed" /> 

       <android.support.v4.view.ViewPager 
        android:id="@+id/pager" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_alignParentStart="true" 
        android:layout_below="@+id/tabLayout" /> 

      </RelativeLayout> 
     </RelativeLayout> 
    </ScrollView> 

</RelativeLayout> 

回答

1
<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"> 

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

    <android.support.design.widget.CollapsingToolbarLayout 
     android:id="@+id/collapsing_toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:contentScrim="?attr/colorPrimary" 
     app:layout_scrollFlags="scroll|exitUntilCollapsed"> 

     <ImageView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@drawable/cartoon" 
      android:scaleType="centerCrop" 
      app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed" 
      app:layout_collapseMode="parallax" /> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      app:layout_collapseMode="pin" /> 

    </android.support.design.widget.CollapsingToolbarLayout> 

    </android.support.design.widget.AppBarLayout> 

    <android.support.v4.widget.NestedScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="#ffe5e5" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

     <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:paddingTop="10dp"> 
     <include layout="@layout/card_layout" /> 
     <include layout="@layout/card_layout" /> 
     <include layout="@layout/card_layout" /> 
     </LinearLayout> 

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

</android.support.design.widget.CoordinatorLayout> 

輸出

enter image description here

Reference

+0

@NoobCoder試試我的代碼,將工作或你可以參考我貼 – vinay

+0

參考鏈接如果它有助於你不忘記upvote – vinay