我正在尝试创建一个底部工作表,该工作表将展开以显示包含文本的嵌套滚动视图。
我正在一个片段中创建它,并得到了带有该片段父级布局的几层布局:
<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是我的底页,包含标题和正文:
<?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>
项目标题:
<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>
还有我的床身:
<?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
}
当我运行上面的代码时,底部标题正确渲染,但是当我展开时,我得到一个空的主体。有谁知道是什么原因导致此问题的?
这个问题原来是我应该使用tools:text
时使用的开发标签android:text