android fragment 高度是100px,如何设置背景撑满屏幕
时间: 2024-03-02 09:51:11 浏览: 19
如果你想让 Fragment 的背景颜色撑满整个屏幕,而不是只占用 100px 的高度,可以使用如下方法:
1. 在 Fragment 布局的根 View 上设置 `android:layout_height="match_parent"`,让它的高度与屏幕高度一致。
2. 设置背景颜色,可以使用 `android:background` 属性,给根 View 设置背景颜色。
示例代码如下:
```
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="100dp"
android:text="Hello World!" />
</LinearLayout>
```
在上面的例子中,LinearLayout 是 Fragment 的根 View,设置了 `android:layout_height="match_parent"` 让它的高度与屏幕高度一致,同时设置了背景颜色为白色(#ffffff),让背景颜色撑满整个屏幕。在 LinearLayout 中有一个 TextView,高度设置为 100dp。