0

ich zur Zeit das Experimentieren mit CoordinatorLayout + AppbarLayout + CollapsingToolbarLayout in einer Art und Weise, so dass:Wie mache ich eine Scrollbare TextView in CollapsingToolbar?

1) Blättern Sie in der AppBar down "Toolbar" mit [No Nested Scroll/RecyclerView].

2) Der Inhalt unterhalb der Appbar sollte sich mit dem Appbar Scrolling bewegen.

3) Mehrere Bilder unter ViewPager gespeichert.

4) Das letzte Element im ViewPager wäre eine Textansicht.

I 1 erreicht haben) und 2) mit dem folgenden Aufbau:

<?xml version="1.0" encoding="utf-8"?> 

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

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

     <android.support.design.widget.CollapsingToolbarLayout 
      android:id="@+id/flexible.example.collapsing" 
      android:layout_width="match_parent" 
      android:layout_height="300dp" 
      app:expandedTitleMarginBottom="94dp" 
      app:layout_scrollFlags="scroll|exitUntilCollapsed|snap" 
      app:contentScrim="?colorPrimary" 
      > 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_margin="10dp" 
       android:id="@+id/text_sample" 
       android:scrollbars="vertical" 
       android:scrollIndicators="right" 
       app:layout_collapseMode="parallax" 
       app:layout_scrollFlags="scroll|enterAlways" 
       android:layout_gravity="center" 
       android:nestedScrollingEnabled="true" 
       /> 
     </android.support.design.widget.CollapsingToolbarLayout> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/ioexample.toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="@color/PM01" 
      android:elevation="4dp" 
      app:layout_collapseMode="pin" 
      app:layout_anchor="@id/flexible.example.collapsing" 
      app:layout_anchorGravity="bottom" 
      app:theme="@style/ThemeOverlay.AppCompat.Light" 
      style="@style/ToolBarWithNavigationBack" 
      app:layout_scrollFlags="scroll|enterAlways|snap" 
      > 

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


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

    <android.support.v7.widget.RecyclerView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/recyclerviewcontainer" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 

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

Was ich versuche jetzt zu erreichen, ist das Textview innerhalb collpasingtoolbarlayout zu machen, ist scrollbaren (# 4 oben sein). Da meine Suche bis jetzt mich dazu gebracht hat zu glauben, dass die Appbar alle Berührungsereignisse selbst behandelt, scheint dies nicht einfach zu sein. Aber da es eine Voraussetzung ist, wäre ich mehr als glücklich, eine Anleitung/Hinweise zu haben, die mir helfen, dies zu vervollständigen.

Kann mir bitte jemand sagen, was und wo für diese Funktionalität zu suchen.

Antwort

0

Nach viel Forschung und einige weitere Suche durch SO, bekam ich eine Ahnung, was ich damit tun müssen, um die gewünschte Wirkung zu erzielen:

1) Implementieren Sie ein benutzerdefiniertes Verhalten für appbarlayout:

public class AppBarLayoutCustomBehavior extends AppBarLayout.Behavior { 
    private boolean setIntercept = false; 
    private boolean lockAppBar = false; 

    DragCallback mDragCallback = new DragCallback() { 
     @Override 
     public boolean canDrag(@NonNull AppBarLayout appBarLayout) { 
      return !lockAppBar; 
     } 
    }; 

    @Override 
    public boolean onInterceptTouchEvent(CoordinatorLayout parent, AppBarLayout child, MotionEvent ev) { 
     super.onInterceptTouchEvent(parent, child, ev); 
     return setIntercept; 
    } 

    public void setInterceptTouchEvent(boolean set) { 
     setIntercept = set; 
    } 

    public AppBarLayoutCustomBehavior() { 
     super(); 
     setDragCallback(mDragCallback); 
    } 

    public AppBarLayoutCustomBehavior(Context ctx, AttributeSet attributeSet) { 
     super(ctx, attributeSet); 
     setDragCallback(mDragCallback); 
    } 

    public void lockAppBar() { 
     lockAppBar = true; 
    } 

    public void unlockAppBar() { 
     lockAppBar = false; 
    } 
} 

2) Verwenden sie dieses kundenspezifische Verhalten mit App-Leiste:

CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams)appBarLayout.getLayoutParams(); 
     final AppBarLayoutCustomBehavior mBehavior = new AppBarLayoutCustomBehavior(); 
     lp.setBehavior(mBehavior); 

/// use toolbar to enable/disable dragging on the appbar behavior. This way 
/// out toolbar acts as a drag handle for the app bar. 
     Toolbar toolbar = (Toolbar) activity.findViewById(R.id.main_toolbar); 
     toolbar.setOnTouchListener(new View.OnTouchListener() { 
      @Override 
      public boolean onTouch(View v, MotionEvent event) { 
       switch(event.getAction()) { 
        case MotionEvent.ACTION_DOWN: 
         mBehavior.setInterceptTouchEvent(true); 
         return true; 
        case MotionEvent.ACTION_CANCEL: 
         mBehavior.setInterceptTouchEvent(false); 
         return true; 
       } 
       return false; 
      } 
     }); 

3) Setzen sie Bewegung Methode auf dem Textview es scrollbaren zu machen

textView.setMovementMethod(ScrollingMovementMethod.getInstance());