【发布时间】:2021-05-25 17:35:56
【问题描述】:
我对 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>
活动布局是这样的:
<?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" />
我尝试了其他几个根视图组,但最终结果始终相同。
【问题讨论】:
标签: android layout android-wear-2.0