android 布局xml中 android:fitsSystemWindows="true"的作用

本文详细解释了Android布局中使用android:fitsSystemWindows=true属性的作用,如何通过该属性调整视图布局以适应系统窗口,如状态栏。文章还提供了实例说明如何在应用中应用此属性,确保布局与设备系统窗口完美融合。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


android 布局xml中 android:fitsSystemWindows="true"的原文解析为:

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.

内置的一个布尔值属性,通过其去调整基于系统窗口的视图布局,例如状态栏,如果该值为真,调整这个视图的内边距与系统窗口的距离,只有该view是non-embedded(非嵌入的)的activity才会产生影响。

即在开放过程中设计应用程序布局时当考虑当系统窗口的影响时,设置该值,如果为true,将自动调整系统窗口布局来适应你自定义的布局。例如:当系统有状态栏,你的应用也存在状态栏时便可以设置为ture。

转载于:https://my.oschina.net/zaizaiangels/blog/634267

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/main" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity"> <!-- 语言选择器 --> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:orientation="horizontal"> <Spinner android:id="@+id/language_spinner1" android:layout_width="0dp" android:layout_height="50dp" android:layout_marginRight="10dp" android:layout_weight="1" /> <Spinner android:id="@+id/language_spinner2" android:layout_width="0dp" android:layout_height="50dp" android:layout_marginLeft="10dp" android:layout_weight="1" /> </LinearLayout> <!-- 消息列表(占满中间空间) --> <ListView android:id="@+id/messageListView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:divider="@android:color/transparent" android:dividerHeight="8dp" android:padding="16dp" /> <!-- 用ScrollView包裹输入区域,确保键盘弹出时可滚动 --> <ScrollView android:layout_width="match_parent" android:layout_height="wrap_content" android:fillViewport="true"> <!-- 关键:确保ScrollView占满可用空间 --> <!-- 输入区域 --> <LinearLayout android:id="@+id/line1" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#F5F5F5" android:orientation="horizontal" android:padding="8dp"> <!-- 语音/键盘切换按钮 --> <ImageButton android:id="@+id/voiceTextToggleButton" android:layout_width="45dp" android:layout_height="45dp" android:layout_gravity="center_vertical" android:background="@mipmap/icon_shengbo" android:padding="8dp" /> <!-- 文字输入框 --> <EditText android:id="@+id/textInputEditText" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginLeft="4dp" android:layout_marginRight="4dp" android:layout_weight="1" android:background="@android:color/white" android:ems="10" android:gravity="top" android:hint="输入消息..." android:minHeight="48dp" android:padding="12dp" /> <!-- 语音输入按钮(默认隐藏) --> <Button android:id="@+id/recordButton" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginLeft="4dp" android:layout_marginRight="4dp" android:layout_weight="1" android:text="按住 说话" android:textColor="#FFFFFF" android:visibility="gone" android:textSize="16sp" /> </LinearLayout> </ScrollView> </LinearLayout>帮我解决点击输入框后键盘遮挡输入框
07-22
<com.google.android.material.appbar.AppBarLayout android:id="@+id/app_bar" android:layout_width="match_parent" android:layout_height="wrap_content" android:fitsSystemWindows="true" android:importantForAccessibility="no" app:elevation="0dp" app:layout_constraintTop_toTopOf="parent"> <com.google.android.material.appbar.CollapsingToolbarLayout android:id="@+id/collapse_tl" android:layout_width="match_parent" android:layout_height="match_parent" android:importantForAccessibility="no" app:layout_scrollFlags="scroll|exitUntilCollapsed|snapMargins" app:titleEnabled="true" app:toolbarId="@+id/toolbar"> <View android:id="@+id/profile_bg_iv" android:layout_width="match_parent" android:layout_height="match_parent" android:alpha="0" android:background="?attr/colorSurface" app:layout_collapseMode="parallax" /> <androidx.constraintlayout.widget.ConstraintLayout android:id="@+id/profile_cl" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="?attr/actionBarSize" android:layout_marginBottom="10dp" app:layout_collapseMode="parallax" app:layout_collapseParallaxMultiplier="0.6"> <com.google.android.material.imageview.ShapeableImageView android:id="@+id/profile_iv" android:layout_width="@dimen/tpds_all_dp_76" android:layout_height="@dimen/tpds_all_dp_76" android:scaleType="centerCrop" android:importantForAccessibility="no" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:shapeAppearanceOverlay="@style/ShapeAppearanceOverlay.MP.ShapeableImageView.Circle" app:srcCompat="@mipmap/ic_avatar_default" /> <com.tplink.design.text.TPTextView android:id="@+id/profile_name_tv" style="@style/Widget.TPDesign.TextView.Primary.Title" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginStart="16dp" android:layout_marginTop="10dp" android:layout_marginEnd="16dp" android:focusable="true" android:gravity="center" app:markAsAccessibilityHeader="true" app:layout_constraintTop_toBottomOf="@id/profile_iv" tools:text="Finn" /> <com.tplink.design.button.TPUnderlineButton android:id="@+id/profile_edit_tv" style="@style/Widget.TPDesign.TextView.Highlight.Body1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginHorizontal="@dimen/tpds_all_dp_16" android:layout_marginTop="10dp" android:focusable="true" android:gravity="center" android:minWidth="@dimen/tpds_all_dp_48" android:minHeight="@dimen/tpds_all_dp_48" android:text="@string/parent_control_edit_owner" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintTop_toBottomOf="@id/profile_name_tv" /> </androidx.constraintlayout.widget.ConstraintLayout> <com.google.android.material.appbar.MaterialToolbar android:id="@+id/toolbar" style="@style/Widget.TPDesign.Toolbar" android:layout_width="match_parent" android:layout_height="@dimen/tpds_all_dp_146" android:background="@color/tpds_transparent" app:layout_collapseMode="pin" app:navigationContentDescription="@string/talkback_back" app:navigationIcon="@drawable/mp_svg_nav_arrow_start" app:titleTextColor="?attr/colorSurface" /> </com.google.android.material.appbar.CollapsingToolbarLayout> </com.google.android.material.appbar.AppBarLayout> 这里折叠后的高度是由哪个决定
最新发布
07-23
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值