Tôi đã phát hiện ra rằng nếu bố cục gốc chứa android:fitsSystemWindows="true"
, nó sẽ can thiệp vào vị trí BottomSheets của tôi, khi một hành động liên quan đến xem xảy ra.Android: fitsSystemWindows và dòng mới can thiệp với bottomSheets
Cụ thể là trang tôi đang gặp phải: trong đó một dòng mới trong chế độ xem văn bản sẽ kích hoạt các bảng tính để bù đắp theo chiều cao của thanh hệ thống/notif.
newline + fitsSystemWindows = dìm bottomsheet tôi xuống
tôi loại bỏ tất cả những thứ không liên quan xuống nút, TextView và bottomsheet.
- Button2:
setText("1\n2")
là nơi sự kỳ diệu xảy ra
Ngay sau khi tôi loại bỏandroid:fitsSystemWindows="true"
, đó là tất cả ok, hành vi không lạ hơn, nhưng tôi đã làm mất tác dụng của bao fitsSystemWindows màu sắc trong hệ thống/notif-bar.
Tôi cũng đã cố gắng bố cục bố cục dưới cùng của riêng mình android:fitsSystemWindows="false"
, nhưng nó không có hiệu lực.
Làm cách nào để có thể đạt được cả hai fitsSystemWindows = true nếu không có hành vi bù trừ lạ này trên bottomSheets của tôi?
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>
Xem lại điều này với các thư viện hỗ trợ mới nhất 25.x.x, vấn đề dường như đã biến mất ngay bây giờ. – TWL
chỉ tìm thấy sự cố ở 23.3.0 https://developer.android.com/topic/libraries/support-library/revisions.html liên kết đến https://code.google.com/p/android/issues/detail ? id = 203057 – TWL