1 回答

TA貢獻(xiàn)1808條經(jīng)驗(yàn) 獲得超4個(gè)贊
發(fā)生此錯(cuò)誤是因?yàn)槟幕顒?dòng)無(wú)法找到底部工作表視圖,為什么呢?因?yàn)槟牡撞抗ぷ鞅硪晥D未包含在activity_main.xml布局中。
換句話(huà)說(shuō),您MainActivity.java只能查看activity_main.xml,但它仍然不知道底部工作表的其他 xml 文件。
activity_main要解決此問(wèn)題:將布局中的代碼替換為
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinaCoordinatorLayout
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="match_parent"
tools:context="com.chargesplit.android.activities.MainActivity">
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"/>
<android.support.v4.widget.NestedScrollView
android:id="@+id/nestedScrollView"
android:layout_width="match_parent"
android:layout_height="300dp"
android:background="@android:color/holo_green_light"
android:clipToPadding="true"
app:behavior_hideable="true"
app:behavior_peekHeight="0dp"
app:layout_behavior="@string/bottom_sheet_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ciao"
android:textColor="@android:color/white"
android:textSize="24sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="ciao2"
android:textColor="@android:color/white" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinaCoordinatorLayout>
注意:為了使您的布局看起來(lái)整潔,您可以將底部工作表視圖分離到一個(gè)單獨(dú)的布局中,這樣您就可以將其放入<android.support.v4.widget.NestedScrollView>bottom_sheet.xml中,然后從activity_main.xml中引用它
<include layout="@layout/bottom_sheet" />
希望對(duì)您有所幫助。如果您需要進(jìn)一步的幫助,請(qǐng)告訴我
添加回答
舉報(bào)