BottomSheet body 未正确填充
BottomSheet body not being populated properly
我正在尝试创建一个底部 sheet 展开以显示包含文本的嵌套滚动视图。
我正在一个片段中创建它,并使用片段的 parent 布局获得了几层布局:
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".fragments.MyFragment">
<com.google.ar.sceneform.SceneView
android:id="@+id/myfragment_sceneview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/fullBlack" />
<include layout="@layout/item_sheet" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
item_sheet 是我的屁股 sheet 并且包含一个 header 和一个 body:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/item_sheet"
android:layout_width="@dimen/bottom_sheet_width"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="vertical"
android:theme="@style/ThemeOverlay.MaterialComponents.Light"
app:behavior_hideable="false"
app:behavior_peekHeight="@dimen/bottom_sheet_peek_height"
app:behavior_skipCollapsed="false"
app:layout_behavior="@string/bottom_sheet_behavior"
tools:showIn="@layout/stall_fragment">
<include layout="@layout/item_header" />
<include layout="@layout/item_description_body" />
</LinearLayout>
项目header:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/item_header"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_peek_height"
android:background="@drawable/bottom_sheet_frame"
android:divider="@drawable/material_divider"
android:elevation="@dimen/material_elevation"
android:focusableInTouchMode="false"
android:orientation="horizontal"
android:outlineProvider="background"
android:paddingLeft="@dimen/bottom_sheet_horizontal_padding"
android:paddingRight="@dimen/bottom_sheet_horizontal_padding"
android:showDividers="middle"
tools:showIn="@layout/item_sheet">
<bunch of TextView views>
</LinearLayout>
还有我的屁股sheetbody:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/bottom_sheet_bgc"
android:paddingLeft="@dimen/bottom_sheet_horizontal_padding"
android:paddingRight="@dimen/bottom_sheet_horizontal_padding"
android:paddingBottom="@dimen/material_unit_1"
tools:showIn="@layout/item_sheet">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="@+id/item_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/fullBlack"
tools:text="@string/item_description" />
</androidx.core.widget.NestedScrollView>
</LinearLayout>
我正在我的片段中使用以下方式初始化它:
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
setHasOptionsMenu(true)
val view = inflater.inflate(R.layout.my_fragment, container, false)
return view
}
当我 运行 上面的代码时,底部 header 正确呈现,但是当我展开时我得到一个空的 body。有谁知道是什么导致了这个问题?
问题出在我本应使用 android:text
时却使用了开发标签 tools:text
我正在尝试创建一个底部 sheet 展开以显示包含文本的嵌套滚动视图。
我正在一个片段中创建它,并使用片段的 parent 布局获得了几层布局:
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".fragments.MyFragment">
<com.google.ar.sceneform.SceneView
android:id="@+id/myfragment_sceneview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/fullBlack" />
<include layout="@layout/item_sheet" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
item_sheet 是我的屁股 sheet 并且包含一个 header 和一个 body:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/item_sheet"
android:layout_width="@dimen/bottom_sheet_width"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="vertical"
android:theme="@style/ThemeOverlay.MaterialComponents.Light"
app:behavior_hideable="false"
app:behavior_peekHeight="@dimen/bottom_sheet_peek_height"
app:behavior_skipCollapsed="false"
app:layout_behavior="@string/bottom_sheet_behavior"
tools:showIn="@layout/stall_fragment">
<include layout="@layout/item_header" />
<include layout="@layout/item_description_body" />
</LinearLayout>
项目header:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/item_header"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_peek_height"
android:background="@drawable/bottom_sheet_frame"
android:divider="@drawable/material_divider"
android:elevation="@dimen/material_elevation"
android:focusableInTouchMode="false"
android:orientation="horizontal"
android:outlineProvider="background"
android:paddingLeft="@dimen/bottom_sheet_horizontal_padding"
android:paddingRight="@dimen/bottom_sheet_horizontal_padding"
android:showDividers="middle"
tools:showIn="@layout/item_sheet">
<bunch of TextView views>
</LinearLayout>
还有我的屁股sheetbody:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/bottom_sheet_bgc"
android:paddingLeft="@dimen/bottom_sheet_horizontal_padding"
android:paddingRight="@dimen/bottom_sheet_horizontal_padding"
android:paddingBottom="@dimen/material_unit_1"
tools:showIn="@layout/item_sheet">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="@+id/item_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/fullBlack"
tools:text="@string/item_description" />
</androidx.core.widget.NestedScrollView>
</LinearLayout>
我正在我的片段中使用以下方式初始化它:
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
setHasOptionsMenu(true)
val view = inflater.inflate(R.layout.my_fragment, container, false)
return view
}
当我 运行 上面的代码时,底部 header 正确呈现,但是当我展开时我得到一个空的 body。有谁知道是什么导致了这个问题?
问题出在我本应使用 android:text
tools:text