<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"> <RelativeLayout android:id="@+id/poi_list_container" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@drawable/bg_list_circular" android:visibility="gone"> <ListView android:id="@+id/poi_list" android:layout_width="match_parent" android:layout_height="match_parent" android:hardwareAccelerated="true" android:scrollbars="none" /> </RelativeLayout> <com.baidu.mapapi.map.MapView android:id="@+id/bmapView" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:clickable="true" android:focusable="true" android:hardwareAccelerated="true" /> </LinearLayout> 我想要的结果是 将RelativeLayout包裹的listview放到mapview之后,并且显示在布局的左侧,不占用mapview的空间 ,listview显示出来了,但是它首次加载时listview设置数据了才会显示,这时候mapview向右侧移动,导致出现黑屏,我要解决的是这个问题
时间: 2023-07-19 07:48:11 浏览: 37
这个问题的原因是在listView首次加载时,需要加载数据,这个过程可能需要一些时间,而在这个过程中,mapView可能会先进行绘制,导致出现黑屏。解决这个问题的方法是在listView加载数据之前,先将listView设置为不可见,等数据加载完成后再将其设置为可见。这样就可以避免在数据加载的过程中出现黑屏的情况了。你可以在代码中尝试一下这个方法,看看是否有效。
相关问题
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/poi_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:baselineAligned="false" android:orientation="horizontal"> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <RelativeLayout android:id="@+id/poi_list_container" android:layout_width="360dp" android:layout_height="match_parent" android:layout_above="@id/bmapView" android:background="@drawable/bg_list_circular" android:visibility="gone"> <ListView android:id="@+id/poi_list" android:layout_width="match_parent" android:layout_height="match_parent" android:hardwareAccelerated="true" android:scrollbars="none" /> </RelativeLayout> <!-- <RelativeLayout--> <!-- android:layout_width="0dp"--> <!-- android:layout_height="match_parent"--> <!-- android:layout_weight="3">--> <com.baidu.mapapi.map.MapView android:id="@+id/bmapView" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignParentTop="true" android:clickable="true" android:focusable="true" android:hardwareAccelerated="true" /> </RelativeLayout> </LinearLayout> 这样写的话显示不出来listview,我想要的结果是 将RelativeLayout包裹的listview放到mapview之后,并且显示在布局的左侧,不占用mapview的空间
非常抱歉,我之前的回答仍然有误。您可以尝试以下代码来实现您想要的效果:
```
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/poi_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<RelativeLayout
android:id="@+id/poi_list_container"
android:layout_width="360dp"
android:layout_height="match_parent"
android:background="@drawable/bg_list_circular"
android:visibility="gone">
<ListView
android:id="@+id/poi_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hardwareAccelerated="true"
android:scrollbars="none" />
</RelativeLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.baidu.mapapi.map.MapView
android:id="@+id/bmapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:focusable="true"
android:hardwareAccelerated="true" />
<RelativeLayout
android:layout_width="360dp"
android:layout_height="match_parent"
android:layout_gravity="left"
android:background="@android:color/transparent">
<!-- Add any other views you want to display here -->
</RelativeLayout>
</FrameLayout>
</LinearLayout>
```
这个布局将ListView包裹在RelativeLayout中,并在左侧显示,不占用MapView的空间。通过将RelativeLayout放置在FrameLayout中,可以将其叠加在MapView上,从而实现您想要的效果。
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/poi_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:baselineAligned="false" android:orientation="horizontal"> <RelativeLayout android:id="@+id/poi_list_container" android:layout_width="@dimen/search_relativelayout" android:layout_height="match_parent" android:background="@drawable/bg_list_circular" android:visibility="gone"> <ListView android:id="@+id/poi_list" android:layout_width="match_parent" android:layout_height="match_parent" android:hardwareAccelerated="true" android:scrollbars="none" /> </RelativeLayout> <!-- <RelativeLayout--> <!-- android:layout_width="0dp"--> <!-- android:layout_height="match_parent"--> <!-- android:layout_weight="3">--> <com.baidu.mapapi.map.MapView android:id="@+id/bmapView" android:layout_width="match_parent" android:layout_height="match_parent" android:clickable="true" android:focusable="true" android:hardwareAccelerated="true" /> </LinearLayout> 这是我的layout布局,看看层级正确不正确,你说RelativeLayout应该在mapview的下方,那我要的效果是RelativeLayout包裹的listview要显示在页面左侧
根据你的描述和布局代码,RelativeLayout 放在 MapView 的下方是正确的。如果你想让 RelativeLayout 包裹的 ListView 显示在页面左侧,可以将 LinearLayout 的 orientation 属性设置为 vertical,并在 RelativeLayout 中添加一个宽度为固定值的属性,如下所示:
```
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/poi_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/poi_list_container"
android:layout_width="200dp" // 设置为固定值,即左侧的宽度
android:layout_height="match_parent"
android:background="@drawable/bg_list_circular"
android:visibility="gone">
<ListView
android:id="@+id/poi_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hardwareAccelerated="true"
android:scrollbars="none" />
</RelativeLayout>
<com.baidu.mapapi.map.MapView
android:id="@+id/bmapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:focusable="true"
android:hardwareAccelerated="true" />
</LinearLayout>
```
这样可以让 RelativeLayout 包裹的 ListView 显示在页面左侧,并且 MapView 填充剩余的空间。