问题描述
我对 Wear 项目的片段布局有疑问。我有一个 Wearactivity ,它只托管一个 FragmentContainerView 来支持导航图。在里面我有一个具有以下布局的 HomeFragment:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:BoxedEdges="all">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black"
android:paddingBottom="32dp">
<LinearLayout
android:id="@+id/llWearContent"
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical">
<ImageButton
android:id="@+id/notifications_ibtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|center_horizontal"
android:background="@color/black"
android:src="@drawable/ic_notifications" />
<TextView
android:id="@+id/station_name_tv"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="@dimen/spacing_normal"
android:text="12th St. Oakland City Center Station"
android:textColor="@android:color/white"
android:textStyle="bold" />
<TextView
android:id="@+id/find_station_tv"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="@dimen/spacing_normal"
android:gravity="start"
android:maxLines="1"
android:text="@string/button_find_station"
android:textAlignment="textStart"
android:textAppearance="?attr/textAppearanceButton"
android:textColor="@color/find_change_station_color"
android:textSize="14sp" />
<TextView
android:id="@+id/find_station_tv1"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="@dimen/spacing_normal"
android:gravity="start"
android:maxLines="1"
android:text="@string/button_find_station"
android:textAlignment="textStart"
android:textAppearance="?attr/textAppearanceButton"
android:textColor="@color/find_change_station_color"
android:textSize="14sp" />
<TextView
android:id="@+id/find_station_tv2"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="@dimen/spacing_normal"
android:gravity="start"
android:maxLines="1"
android:text="@string/button_find_station"
android:textAlignment="textStart"
android:textAppearance="?attr/textAppearanceButton"
android:textColor="@color/find_change_station_color"
android:textSize="14sp" />
<TextView
android:id="@+id/find_station_tv3"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="@dimen/spacing_normal"
android:gravity="start"
android:maxLines="1"
android:text="@string/button_find_station"
android:textAlignment="textStart"
android:textAppearance="?attr/textAppearanceButton"
android:textColor="@color/find_change_station_color"
android:textSize="14sp" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
Activity 布局就是这样:
<?xml version="1.0" encoding="utf-8"?>
<androidx.fragment.app.FragmentContainerView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:navGraph="@navigation/nav_graph_wear" />
我尝试了其他几个根视图组,但最终结果总是一样。
解决方法
问题是一个工具栏控制器类,它为活动设置了一个透明的状态栏。真正针对项目。