2

Bir CoordinatorLayout kaydırmasında, en üste geldiğinde kaydırma durur. Böylece kullanıcının görüntüyü görmek için tekrar kaydırması gerekiyor. Görüntü tamamen gösterilinceye kadar kaydırmaya devam etmek mümkün mü?En üst düzeye ulaştığında CollapsingToolbarLayout öğesinde stop kaydırma nasıl engellenir?

<android.support.design.widget.CoordinatorLayout 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" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fitsSystemWindows="true" 
tools:context="com.example.murat.coordinatorlayouttest.ScrollingActivity"> 

<android.support.design.widget.AppBarLayout 
    android:id="@+id/app_bar" 
    android:layout_width="match_parent" 
    android:layout_height="@dimen/app_bar_height" 
    android:fitsSystemWindows="true" 
    android:theme="@style/AppTheme.AppBarOverlay"> 

    <android.support.design.widget.CollapsingToolbarLayout 
     android:id="@+id/collapsing_toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:fitsSystemWindows="true" 
     app:contentScrim="?attr/colorPrimary" 
     app:expandedTitleMarginEnd="64dp" 
     app:expandedTitleMarginStart="48dp" 
     app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"/> 
     <ImageView 
      android:src="@drawable/poster" 
      app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:scaleType="centerCrop" 
      app:layout_collapseMode="parallax" 
      android:minHeight="200dp"/> 

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

<include layout="@layout/content_scrolling" /> 

cevap

0

Sen NestedScrollView yüksekliğini hesaplamak gerekir. Önce xml düzeninizi güncelleyin ve bu özellikleri araç çubuğuna ekleyin ve <includelayout="@layout/content_scrolling" />'un NestedScrollView olduğundan ve kaydırma görünümü davranışına sahip olduğundan emin olun.

app:layout_scrollFlags="scroll|exitUntilCollapsed" 
app:layout_collapseMode="pin" 

Etkinliğinizdeki bu genel değişkenleri tanımlayın.

private int screenHeight; 
    private int linearLayoutHeight; 
    private int toolbarHeight_org; 
    private int toolbarHeight; 

faaliyet onCreate yönteminde bunu yapın

screenHeight = getScreenHeight(this); 

    TypedValue typedValue = new TypedValue(); 
    getTheme().resolveAttribute(R.attr.colorPrimary, typedValue, true); 
    final int colorPrimary = typedValue.data; 

    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
    setSupportActionBar(toolbar); 
    getSupportActionBar().setDisplayHomeAsUpEnabled(true); 

    AppBarLayout appbar = (AppBarLayout) findViewById(R.id.appbar); 
    final CoordinatorLayout.LayoutParams appbarLayoutParams = (CoordinatorLayout.LayoutParams)appbar.getLayoutParams(); 

    final ViewGroup.LayoutParams toolbarLayoutParams = toolbar.getLayoutParams(); 
    if (toolbarLayoutParams != null) { 
     toolbarHeight_org = toolbarLayoutParams.height; 
     toolbarHeight = toolbarLayoutParams.height; 
    } 

    final CollapsingToolbarLayout collapsingToolbar = 
      (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar); 
    collapsingToolbar.setTitle(cheeseName); 

    collapsingToolbar.setContentScrimColor(colorPrimary); 
    collapsingToolbar.setExpandedTitleTextAppearance(R.style.ExpandedTitleTextAppearance); 
    //collapsingToolbar.setCollapsedTitleTextAppearance(R.style.CollapsedTitleTextAppearance); 

    final LinearLayout linearLayout = (LinearLayout) findViewById(R.id.linearLayout1); 
    ViewTreeObserver observer = linearLayout.getViewTreeObserver(); 
    observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { 
     @Override 
     public void onGlobalLayout() { 
      linearLayoutHeight = linearLayout.getHeight(); 
      if (linearLayoutHeight + toolbarHeight < screenHeight) { 
       if (toolbarLayoutParams != null) { 
        toolbarLayoutParams.height = screenHeight - linearLayoutHeight - 20; 
        if (toolbarLayoutParams.height < toolbarHeight_org) { 
         toolbarLayoutParams.height = toolbarHeight_org; 
        } 

        int extended_text_size = (int) getResources().getDimension(R.dimen.expanded_text_size); 

        if (appbarLayoutParams.height - toolbarLayoutParams.height <= extended_text_size) { 
         int value = appbarLayoutParams.height - toolbarLayoutParams.height; 
         if (value < 0) { 
          appbarLayoutParams.height = toolbarLayoutParams.height - value + extended_text_size * 3; 
         } else { 
          appbarLayoutParams.height = toolbarLayoutParams.height + extended_text_size * 3; 
         } 
         if (appbarLayoutParams.height >= screenHeight) { 
          appbarLayoutParams.height = screenHeight; 
         } 
        } 

        // collapsingToolbar.setContentScrimColor(getResources().getColor(android.R.color.transparent)); 
        if (toolbarLayoutParams.height > toolbarHeight_org) { 
         collapsingToolbar.setContentScrimColor(ContextCompat.getColor(mContext, android.R.color.transparent)); 
        } 
       } 
      } 
      // Removes the listener if possible 
      ViewTreeObserver viewTreeObserver = linearLayout.getViewTreeObserver(); 
      if (viewTreeObserver.isAlive()) { 
       if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { 
        linearLayout.getViewTreeObserver().removeGlobalOnLayoutListener(this); 
       } else { 
        linearLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this); 
       } 
      } 
     } 
    }); 
    appbar.setExpanded(true); 
} 

alın Ekran yüksekliği yöntemi Burada

private int getScreenHeight(Context context) { 
    int measuredHeight; 
    Point size = new Point(); 
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); 

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) { 
     wm.getDefaultDisplay().getSize(size); 
     measuredHeight = size.y; 
    } else { 
     Display d = wm.getDefaultDisplay(); 
     measuredHeight = d.getHeight(); 
    } 

    return measuredHeight; 
} 

lütfen bu

göre seninkini güncellemek aktivitenin tamamen xml düzenini olduğunu

<android.support.design.widget.AppBarLayout 
    android:id="@+id/appbar" 
    android:layout_width="match_parent" 
    android:layout_height="@dimen/detail_backdrop_height" 
    android:fitsSystemWindows="true" 
    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" 
     android:fitsSystemWindows="true" 
     app:contentScrim="?attr/colorPrimary" 
     app:layout_scrollFlags="scroll|exitUntilCollapsed"> 

     <ImageView 
      android:id="@+id/backdrop" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:fitsSystemWindows="false" 
      android:scaleType="centerCrop" 
      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" 
      app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 

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

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

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

    <LinearLayout 
     android:id="@+id/linearLayout1" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 

     <android.support.v7.widget.CardView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_margin="@dimen/card_margin"> 

      <LinearLayout 
       style="@style/Widget.CardContent" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="Info" 
        android:textAppearance="@style/TextAppearance.AppCompat.Title" /> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="@string/cheese_ipsum" /> 

      </LinearLayout> 

     </android.support.v7.widget.CardView> 

    </LinearLayout> 

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

+0

Ok i 2 soru 1-Nerede ben bu linearLayout1 koymalıyız var? 2- Bu seçenekleri yuvalanmış görünümde nereye koyayım? app: layout_scrollFlags = "scroll | exitUntilCollapsed" app: layout_collapseMode = "pin" –

+0

put 'app: layout_scrollFlags = "scroll | exitUntilCollapsed" app: layout_collapseMode = "pin" 'xml içindeki araç çubuğunuzda ve' NestedScrollView 'olmalıdır @@ layout/content_scrolling' nin üst öğesi –

+0

Ve ekle: app: layout_behavior = "@ string/appbar_scrolling_view_behavior" 'in xed –