fitSystemWindows属性


官方描述:

        Boolean internal attribute to adjust view layout based on system windows such as the status bar. If true, adjusts the padding of this view to leave space for the system windows. Will only take effect if this view is in a non-embedded activity.

    简单描述:

     这个一个boolean值的内部属性,让view可以根据系统窗口(如status bar)来调整自己的布局,如果值为true,就会调整view的paingding属性来给system windows留出空间....

举例:项目上有一个全屏的界面,界面布局文件如下:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fillViewport="true">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <Button
            android:id="@+id/bottomSheetDialog_button"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="BottomSheetDialog_test"/>

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_margin="20dp"
            android:inputType="number"/>
    </RelativeLayout>
</ScrollView>

布局最外层是ScrollView,为了让布局可以上下伸缩滚动,添加fillViewport属性使得布局垂直填充。为了使得界面达到全屏效果,在java文件中添加如下:

        getWindow().requestFeature(Window.FEATURE_NO_TITLE);
        getWindow().getDecorView().setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                        | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
        setContentView(R.layout.activity_main);

添加完后运行结果

发现顶部按钮和底部编辑框被系统UI(状态栏和输入法)给覆盖了。添加fitSystemWindows属性就可以解决这个问题:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fillViewport="true"
    android:fitsSystemWindows="true">



  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android R 中,全屏手势识别可以通过使用新的 GestureNavigation API 来实现。下面是一个简单的实现示例: 1. 在你的 Activity 中,设置 Window属性以启用全屏手势识别: ```java if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { getWindow().setDecorFitsSystemWindows(false); getWindow().setInsetsController(new WindowInsetsController.Builder(getWindow(), getWindow().getDecorView()) .setSystemBarsBehavior(WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE) .build()); } ``` 2. 在你的布局文件中,将根布局的 fitSystemWindows 属性设置为 false: ```xml <androidx.constraintlayout.widget.ConstraintLayout android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="false"> ... </androidx.constraintlayout.widget.ConstraintLayout> ``` 3. 在你的 Activity 中,实现 OnSwipeGestureListener 接口来处理手势事件: ```java public class MyActivity extends AppCompatActivity implements OnSwipeGestureListener { private final GestureNavigationController gestureNavigationController = new GestureNavigationController(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // ... gestureNavigationController.setSwipeGestureListener(this); } @Override public void onSwipeLeft() { // 处理向左滑动手势 } @Override public void onSwipeRight() { // 处理向右滑动手势 } @Override public void onSwipeUp() { // 处理向上滑动手势 } @Override public void onSwipeDown() { // 处理向下滑动手势 } } ``` 以上就是 Android R 中实现全屏手势识别的简单示例。当然,具体实现还需要根据你的需求进行调整和完善。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值