Android:fitsSystemWindows和换行干扰bottomSheets [英] Android: fitsSystemWindows and newline interfering with bottomSheets

查看:112
本文介绍了Android:fitsSystemWindows和换行干扰bottomSheets的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现,如果父布局包含 android:fitsSystemWindows = true ,则在发生与视图相关的操作时,它将干扰我的BottomSheets定位。

I have found out that if the parent layout contains android:fitsSystemWindows="true", it will interfere with my BottomSheets positioning, when a view-related action happens.

特别是我遇到的那个:在文本视图中的换行符将触发底表偏移系统/ notif-bar的高度。

Specifically the one I'm encountering: where a newline in a textview will trigger the bottomsheets to offset by the height of the system/notif-bar.

换行符+ fitsSystemWindows =将我的底表压倒

我消除了所有无关紧要的内容,直到按钮为止, textview和底部表格。

I eliminated all irrelevant stuff down to buttons, textview and the bottomsheet.


  • Button2: setText( 1\n2)是魔术发生的地方

  • Button2: setText("1\n2") is where the magic happens

删除 android:fitsSystemWindows = true ,一切正常,没有其他奇怪的行为,但是我失去了system / notif-bar中fitsSystemWindows颜色的效果。

As soon as I remove android:fitsSystemWindows="true", it's all ok, no more strange behavior, but I lose the effect of how fitsSystemWindows colors in the system/notif-bar.

我还尝试给我的bottomSheet布局提供自己的 android:fitsSystemWindows = false ,但是它没有

I also tried to give my bottomSheet layout its own android:fitsSystemWindows="false", but it has had no effect.

如何在我的bottomSheets上没有这种奇怪的偏移行为的情况下同时实现fitsSystemWindows = true?

亲自去看看!

See for yourself!

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

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>


推荐答案

即使使用支持库25.1,我也遇到类似的问题.0。但是后来我发现这可能是因为未使用CollapsingToolbarLayout。我将其包含在内并爆炸!..即使由于换行而导致任何布局更改后,它仍能正常运行

I too had a similar problem even with support library 25.1.0. But I later figured out that it could have been because of not using a CollapsingToolbarLayout. I included it and bang!.. it is behaving normally even after any layout changes due to linebreaks

这篇关于Android:fitsSystemWindows和换行干扰bottomSheets的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆