15

Ich habe vor kurzem beschlossen, meine App auf die neue Support-Design-Bibliothek zu verschieben, und vor kurzem einen sehr bösen Bug entdeckt.CoordinatorLayout mit CollapsingToolbarLayout bricht mit Tastatur im Dialog Fragment

Angenommen, ich habe ein CoordinatorLayout, das ein AppBarLayout und eine scrollbare Ansicht hostet, sei es ein ViewPager, NestedScrollView oder sogar ein RecyclerView mit dem erforderlichen Scroll-Verhalten; Wenn Sie ein Dialogfeldfragment anzeigen, das die Tastatur anzeigt, wird die Verbindung zwischen AppBarLayout und der Scroll-Ansicht aufgehoben, und sie scrollen nicht mehr zusammen.

Darüber hinaus ist die Scroll-Ansicht gezwungen, die Größe auf die Hälfte des Bildschirms am unteren Rand zu ändern, und das AppBar-Layout nimmt die obere Hälfte, obwohl es nicht benötigt wird.

Ein Video des Fehlers ist hier: Youtube Link

EDIT:

in der Aktivität der die softInputMode der Tastatur Einstellung "adjustPan" das Problem behebt. Anscheinend möchte das CoordinatorLayout nicht dynamisch von der Tastatur skaliert werden.

Der fehlbare XML sieht so aus, aber ich habe mehrere XML-Variationen, die dieses Verhalten zeigen, mit dem gemeinsamen Element unter ihnen allen sie ein CollapsingToolbarLayout verwenden sein: auf Ihr Android

<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:orientation="vertical"> 

<android.support.v4.view.ViewPager 
    android:id="@+id/pager" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 

<android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="192dp" 
    android:background="@color/transparent"> 

    <android.support.design.widget.CollapsingToolbarLayout 
     android:id="@+id/collapsing_toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="144dp" 
     android:elevation="4dp" 
     app:contentScrim="?attr/colorPrimary" 
     app:expandedTitleMarginBottom="@dimen/quadruple_margin" 
     app:layout_collapseParallaxMultiplier="0.7" 
     app:layout_scrollFlags="scroll|exitUntilCollapsed"> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:animateLayoutChanges="true" 
      android:background="@color/primary" 
      android:orientation="vertical"> 

      <ImageView 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_gravity="bottom" 
       android:adjustViewBounds="true" 
       android:scaleType="centerCrop" 
       android:src="@drawable/ranking_background" /> 

      <View 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_alignParentTop="true" 
       android:layout_gravity="bottom" 
       android:background="@color/black_40" /> 

      <de.hdodenhof.circleimageview.CircleImageView 
       android:id="@+id/profile_picture" 
       android:layout_width="@dimen/double_margin" 
       android:layout_height="@dimen/double_margin" 
       android:layout_alignBottom="@+id/text" 
       android:layout_marginLeft="@dimen/double_margin" 
       android:layout_marginStart="@dimen/double_margin" 
       android:src="@drawable/image_placeholder" 
       android:visibility="gone" /> 

      <TextView 
       android:id="@+id/text" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignParentTop="true" 
       android:layout_alignWithParentIfMissing="true" 
       android:layout_marginLeft="@dimen/single_margin" 
       android:layout_marginStart="@dimen/single_margin" 
       android:layout_marginTop="@dimen/quadruple_margin" 
       android:layout_toRightOf="@+id/profile_picture" 
       android:text="@string/my_places_for" 
       android:textColor="@color/white" 
       android:textSize="20sp" 
       android:visibility="gone" /> 

      <TextView 
       android:id="@+id/sub_text" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_below="@+id/text" 
       android:layout_marginLeft="@dimen/single_margin" 
       android:layout_marginStart="@dimen/single_margin" 
       android:layout_marginTop="@dimen/single_margin" 
       android:text="@string/pick_category_or_business" 
       android:textColor="@color/white" 
       android:textSize="16sp" 
       android:visibility="gone" /> 
     </RelativeLayout> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/action_bar" 
      android:layout_width="match_parent" 
      android:layout_height="@dimen/abc_action_bar_default_height_material" 
      app:contentInsetLeft="@dimen/triple_margin" 
      app:contentInsetStart="@dimen/triple_margin" 
      app:layout_collapseMode="pin" 
      app:popupTheme="@style/Theme.AppCompat.NoActionBar" 
      app:theme="@style/Theme.AppCompat.NoActionBar" /> 
    </android.support.design.widget.CollapsingToolbarLayout> 

    <android.support.design.widget.CollapsingToolbarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@color/primary" 
     app:layout_scrollFlags="scroll"> 

     <android.support.design.widget.TabLayout 
      android:id="@+id/tabs" 
      android:layout_width="match_parent" 
      android:layout_height="48dp" 
      android:layout_alignParentBottom="true" 
      android:background="@color/primary" 
      android:elevation="4dp" 
      app:layout_scrollFlags="enterAlways" 
      app:tabGravity="fill" 
      app:tabMode="fixed" 
      app:tabSelectedTextColor="@color/white" 
      app:tabTextColor="@color/grey_400" /> 
    </android.support.design.widget.CollapsingToolbarLayout> 
</android.support.design.widget.AppBarLayout> 

Antwort

9

die Antwort von Tunji_D zur Verfügung gestellt wird, das Problem, aber nicht unbedingt die unter lösen Lügenproblem.

Das Scroll-Verhalten auf dem Koordinator Layout hat ein Problem gerade jetzt während des Ungültigkeits Schrittes auf seinem Kind Ansichten: https://code.google.com/p/android/issues/detail?id=176373#c5

Also, um es zu beheben diese Abhilfe durch junya bereitgestellt verwenden, und legen Sie das Verhalten Ihrer Ansicht der mit

app:layout_behavior="com.app.common.PatchedScrollingViewBehavior" 

und Verwendung:

public class PatchedScrollingViewBehavior extends AppBarLayout.ScrollingViewBehavior { 

    public PatchedScrollingViewBehavior() { 
     super(); 
    } 

    public PatchedScrollingViewBehavior(Context context, AttributeSet attrs) { 
     super(context, attrs); 
    } 

    @Override 
    public boolean onMeasureChild(CoordinatorLayout parent, View child, int parentWidthMeasureSpec, int widthUsed, int parentHeightMeasureSpec, int heightUsed) { 
     if(child.getLayoutParams().height == -1) { 
      List dependencies = parent.getDependencies(child); 
      if(dependencies.isEmpty()) { 
       return false; 
      } 

      AppBarLayout appBar = findFirstAppBarLayout(dependencies); 
      if(appBar != null && ViewCompat.isLaidOut(appBar)) { 
       if(ViewCompat.getFitsSystemWindows(appBar)) { 
        ViewCompat.setFitsSystemWindows(child, true); 
       } 

       int scrollRange = appBar.getTotalScrollRange(); 
//    int height = parent.getHeight() - appBar.getMeasuredHeight() + scrollRange; 
       int parentHeight = View.MeasureSpec.getSize(parentHeightMeasureSpec); 
       int height = parentHeight - appBar.getMeasuredHeight() + scrollRange; 
       int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.AT_MOST); 
       parent.onMeasureChild(child, parentWidthMeasureSpec, widthUsed, heightMeasureSpec, heightUsed); 
       return true; 
      } 
     } 

     return false; 
    } 


    private static AppBarLayout findFirstAppBarLayout(List<View> views) { 
     int i = 0; 

     for(int z = views.size(); i < z; ++i) { 
      View view = (View)views.get(i); 
      if(view instanceof AppBarLayout) { 
       return (AppBarLayout)view; 
      } 
     } 

     return null; 
    } 
} 
6

Go manifestieren und den „Window Soft-Input-Modus“ ändern:

android:windowSoftInputMode="adjustPan|adjustNothing" 
+0

perfekte Jungs! Danke vielmals ! – anthony

0

Versuchen Aktualisierung auf die neueste der com.android.support:appcompat - Arbeitete für mich.