亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Android studio Java - 地圖上的底部工作表視圖

Android studio Java - 地圖上的底部工作表視圖

慕田峪4524236 2023-08-16 18:05:41
對于android編程,java新手,我正在嘗試創建一個“簡單..”BottomSheet,當我單擊我的位置之一時,它必須出現。實際上我已經能夠創建我的地圖并加載我的點數據。我的地圖在一個片段中..    <?xml version="1.0" encoding="utf-8"?>    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent"     android:layout_height="fill_parent"><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"    /></RelativeLayout>然后我查看在線教程創建了我的 BottomSheet。<?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"> <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">    </LinearLayout></android.support.v4.widget.NestedScrollView></android.support.design.widget.CoordinaCoordinatorLayout>
查看完整描述

1 回答

?
炎炎設計

TA貢獻1808條經驗 獲得超4個贊

發生此錯誤是因為您的活動無法找到底部工作表視圖,為什么呢?因為您的底部工作表視圖未包含在activity_main.xml布局中。


換句話說,您MainActivity.java只能查看activity_main.xml,但它仍然不知道底部工作表的其他 xml 文件。


activity_main要解決此問題:將布局中的代碼替換為


<?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>

注意:為了使您的布局看起來整潔,您可以將底部工作表視圖分離到一個單獨的布局中,這樣您就可以將其放入<android.support.v4.widget.NestedScrollView>bottom_sheet.xml中,然后從activity_main.xml中引用它


<include layout="@layout/bottom_sheet" />

希望對您有所幫助。如果您需要進一步的幫助,請告訴我


查看完整回答
反對 回復 2023-08-16
  • 1 回答
  • 0 關注
  • 120 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號