activity怎么使底部的控件不被顶上去,布局怎么写,详细代码
时间: 2024-03-20 18:40:31 浏览: 22
要实现这个效果,可以使用 Android 中的 `android:windowSoftInputMode` 属性,它可以设置输入法模式,其中 `adjustResize` 模式可以让底部的控件不被顶上去。这个属性可以在 `AndroidManifest.xml` 中设置:
```
<activity
android:name=".YourActivity"
android:windowSoftInputMode="adjustResize">
...
</activity>
```
此外,为了让布局达到想要的效果,建议使用 `CoordinatorLayout` 作为根布局,将底部的控件放在 `BottomNavigationView` 中。以下是一个简单的示例代码:
```
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- 这里放置 Toolbar 或者其他的 AppBar 控件 -->
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="@dimen/bottom_navigation_height"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<!-- 这里放置主要内容的布局 -->
</FrameLayout>
<android.support.design.widget.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_navigation_height"
android:layout_gravity="bottom"
app:menu="@menu/bottom_navigation_menu" />
</android.support.design.widget.CoordinatorLayout>
```
其中,`@dimen/bottom_navigation_height` 是一个在 `res/values/dimens.xml` 中定义的值,表示底部导航栏的高度;`@menu/bottom_navigation_menu` 是一个在 `res/menu/` 目录下定义的菜单文件,用于设置底部导航栏的菜单项。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)