2016-08-05 15 views
5

Dowiedziałem się, że jeśli układ nadrzędny zawiera android:fitsSystemWindows="true", zakłóci to moje pozycjonowanie w BottomSheets, gdy nastąpi akcja związana z wyświetlaniem.Android: fitsSystemWindows i newline zakłócające dolne arkusze

W szczególności ten, który napotykam: gdzie wiersz w wyglądzie tekstowym wyzwoli arkusze dolne do przesunięcia o wysokość układu/paska adresu.

nowalinia + fitsSystemWindows = rzuca mój bottomsheet dół

I wyeliminowane wszystkie istotne rzeczy do przycisków, TextView i bottomsheet.

  • Button2: setText("1\n2"), gdzie dzieje się magia

Jak tylko usunąćandroid:fitsSystemWindows="true", to wszystko jest w porządku, nie ma bardziej dziwne zachowanie, ale tracą wpływ na to, jak fitsSystemWindows kolorów w systemie/notif-bar.

Próbowałem również ustawić mój układ bottomSheet jako własny android:fitsSystemWindows="false", ale nie przyniósł on żadnego efektu.

Jak mogę osiągnąć oba fitsSystemWindows = true bez tego dziwnego zachowania offsetowego w moich arkuszach dolnych?

Zobacz sam! enter image description here

public class Test extends AppCompatActivity { 
    private BottomSheetBehavior bottomSheetBehavior; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.act_test); 

     LinearLayout bottomSheet = (LinearLayout) findViewById(R.id.root_btmsheet); 
     bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet); 
     bottomSheet.post(new Runnable() { 
      @Override 
      public void run() { 
       bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); 
      } 
     }); 

     ((Button) findViewById(R.id.btn1)).setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 
       ((TextView) findViewById(R.id.info1)).setText("1"); 
      } 
     }); 
     ((Button) findViewById(R.id.btn2)).setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 
       // the culprit, Mr. Newline 
       ((TextView) findViewById(R.id.info1)).setText("1\n2"); 
      } 
     }); 
    } 
} 

act_test.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" <-- the other culprit, Ms. Fits 
    tools:context=".Test"> 

    <!--<include layout="@layout/act_test_content" />--> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" 
     android:orientation="vertical" 
     android:id="@+id/root_content"> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal"> 
      <Button 
       android:id="@+id/btn1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="1" /> 
      <Button 
       android:id="@+id/btn2" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="2" /> 
     </LinearLayout> 

     <TextView 
      android:id="@+id/info1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="#e0e0e0" /> 

    </LinearLayout> 

    <!--<include layout="@layout/act_test_btmsheet" />--> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="200dp" 
     app:layout_behavior="@string/bottom_sheet_behavior" 
     android:orientation="vertical" 
     app:behavior_hideable="false" 
     app:behavior_peekHeight="50dp" 
     android:background="#5533b5e5" 
     android:id="@+id/root_btmsheet"> 

    </LinearLayout> 

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

Powtórne to z najnowszymi bibliotekami pomocniczymi 25.x.x, problem wydaje się już nieobecny. – TWL

+0

Właśnie znalazłem problem na 23.3.0 https://developer.android.com/topic/libraries/support-library/revisions.html linki do https://code.google.com/p/android/issues/detail ? id = 203057 – TWL

Odpowiedz

0

ja też miałem podobny problem nawet z biblioteki wsparcia 25.1.0. Ale później zorientowałem się, że mogło to być spowodowane tym, że nie używano CollapsingToolbarLayout. Zawarłem to i zadziwiłem! ... zachowuje się normalnie nawet po zmianie układu w związku z rozłączeniem linii