gpt4 book ai didi

android - 布局问题,无法与 map 交互

转载 作者:行者123 更新时间:2023-11-30 01:40:04 26 4
gpt4 key购买 nike

我需要一些布局方面的帮助。我有一张 map 、一个抽屉、一个抽屉按钮和一个用于保存自动完成搜索框的卡片 View 。一切看起来都很好,除了我无法与 map 互动。双指缩放、滑动移动和“我的位置”按钮不起作用。我认为这是因为布局错误,我实际上并没有与 map 交互,而是与其他东西交互。在下面发布我的布局。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
map:uiZoomControls="true"
map:uiZoomGestures="true"
map:mapType="normal"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MapsActivity">

<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MapsActivity">

<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<RelativeLayout
android:id="@+id/LeftDrawer"
android:layout_width="200dp"
android:layout_marginTop="60dp"
android:layout_height="500dp"
android:layout_gravity="start"
android:background="@drawable/layout_bg" >

<TextView
android:id="@+id/TitleTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:textColor="@android:color/darker_gray"
android:text="Test Title" />

<ListView
android:id="@+id/navList"
android:layout_width="200dp"
android:layout_height="match_parent"
android:layout_marginTop="30dp"
android:layout_marginBottom="30dp"
android:layout_gravity="left|start"
android:background="@drawable/layout_bg"/>

<TextView
android:id="@+id/TitleTextView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="240dp"
android:textColor="@android:color/darker_gray"
android:text="Test Title 2" />

<Button
android:id="@+id/test_button1"
android:layout_width="30dp"
android:layout_marginTop="270dp"
android:layout_marginLeft="20dp"
android:layout_height="30dp"
android:layout_gravity="left|start"
android:background="@drawable/settings"/>

<Button
android:id="@+id/test_button2"
android:layout_width="30dp"
android:layout_marginTop="270dp"
android:layout_marginLeft="60dp"
android:layout_height="30dp"
android:layout_gravity="left|start"
android:background="@drawable/settings"/>

</RelativeLayout>
</android.support.v4.widget.DrawerLayout>

<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_gravity="top"
android:layout_marginTop="17dp"
android:layout_marginLeft="50dp"
android:layout_width="260dp"
android:layout_height="30dp"
card_view:cardCornerRadius="4dp">

<fragment
android:id="@+id/place_autocomplete_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment" />
</android.support.v7.widget.CardView>

<Button
android:id="@+id/drawer_button"
android:layout_width="30dp"
android:layout_marginTop="17dp"
android:layout_marginLeft="5dp"
android:layout_height="30dp"
android:layout_gravity="left|start"
android:onClick="OpenCloseDrawer"
android:background="@drawable/settings"/>

</fragment>
</LinearLayout>

编辑:发布应用程序的屏幕截图。左上角的按钮是打开/关闭抽屉按钮。如屏幕截图所示,enter image description here该按钮 (@+id/drawer_button) 变得不可访问。当触摸到外面时,抽屉会关闭,但我在那个按钮中有代码,因为按钮不可访问,所以永远不会触发。所以我想始终可以访问按钮,以及可能检测抽屉关闭的某种方式,所以我可以在该事件中使用与我在按钮中使用的代码相同的代码,以防用户只是在外面滑动/触摸关上抽屉。

这是我现在的布局。

activity_maps.xml

<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<include android:id="@+id/map" layout="@layout/fragment" />

<RelativeLayout
android:id="@+id/whatYouWantInLeftDrawer"
android:layout_width="200dp"
android:layout_marginTop="60dp"
android:layout_height="500dp"
android:layout_gravity="start"
android:background="@drawable/layout_bg" >

<TextView
android:id="@+id/TitleTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:textColor="@android:color/darker_gray"
android:text="Title1" />

<ListView
android:id="@+id/navList"
android:layout_width="200dp"
android:layout_height="match_parent"
android:layout_marginTop="30dp"
android:layout_marginBottom="30dp"
android:layout_gravity="left|start"
android:background="@drawable/layout_bg"/>

<TextView
android:id="@+id/TitleTextView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="240dp"
android:textColor="@android:color/darker_gray"
android:text="Ttitle2" />

<Button
android:id="@+id/test_button1"
android:layout_width="30dp"
android:layout_marginTop="270dp"
android:layout_marginLeft="20dp"
android:layout_height="30dp"
android:layout_gravity="left|start"
android:background="@drawable/settings"/>

<Button
android:id="@+id/test_button2"
android:layout_width="30dp"
android:layout_marginTop="270dp"
android:layout_marginLeft="60dp"
android:layout_height="30dp"
android:layout_gravity="left|start"
android:background="@drawable/settings"/>

</RelativeLayout>
</android.support.v4.widget.DrawerLayout>

fragment .xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
map:uiZoomControls="true"
map:uiZoomGestures="true"
map:mapType="normal"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MapsActivity">

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<Button
android:id="@+id/drawer_button"
android:layout_width="30dp"
android:layout_marginTop="17dp"
android:layout_marginLeft="5dp"
android:layout_height="30dp"
android:layout_gravity="left|start"
android:onClick="OpenCloseDrawer"
android:background="@drawable/settings"/>

<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MapsActivity">

<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_gravity="top"
android:layout_marginTop="17dp"
android:layout_marginLeft="50dp"
android:layout_width="240dp"
android:layout_height="30dp"
card_view:cardCornerRadius="4dp">

<fragment
android:id="@+id/place_autocomplete_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment" />
</android.support.v7.widget.CardView>
</fragment>
</FrameLayout>
</LinearLayout>

最佳答案

你需要明白的是,你将只有两个这样的 child

<android.support.v4.widget.DrawerLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

< first View, here you will have your google map/>

< second View, here you will have your ListView/>

</android.support.v4.widget.DrawerLayout>

现在的问题是您不只是有一个普通的谷歌地图显示为第一个 View ,您可以做的是创建一个单独的 fragment 来替换您的第一个 View ,

有很多方法可以做到这一点,具体取决于你想用它实现什么,只要你为 DrawerLayout

保持这种模式,它就可以正常工作

为了简单起见,创建包含 google map 和您的 cardview

的 fragment

fragment .xml

<LinearLayout>

<FrameLayout>
<GoogleMapFragment
android:layout_width="match_parent"
android:layout_height="match_parent"/>

<CardView
android:layout_width="280dp"
android:layout_height="?attr/actionBarSize"/>

</FrameLayout>

</LinearLayout>

现在像这样对您的抽屉导航布局进行一些更改

<android.support.v4.widget.DrawerLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<first View, include fragment & class representing that stuff/>

< second View, here you will have your ListView/>

</android.support.v4.widget.DrawerLayout>

这只是您实现自己的布局的示例:

Update

<FrameLayout>
<android.support.v4.widget.DrawerLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<first View, include fragment & class representing that stuff/>

< second View, here you will have your ListView
margin="leave enough margin to top as you will have buttons, otherwise button will overlap listview"
/>

</android.support.v4.widget.DrawerLayout>

<LinearLayout>

<put your button Views here, so these will appear all the time/>
</LinearLayout>

</FrameLayout>

关于android - 布局问题,无法与 map 交互,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34607496/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com