在安卓中的一个layout中,写了一个listview和一个百度地图的MapView,其中listview先隐藏掉,从别的地方来到这个Activity中去搜索poi后,拿到数据才显示这个listview,然后点击条目去跳转到另一个Activity,跳转的同时把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:id="@+id/poi_list_container" android:layout_width="360dp" android:layout_height="wrap_content" 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: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" /> </RelativeLayout> </LinearLayout>
时间: 2023-11-27 08:51:15 浏览: 111
这个问题可能是由于ListView的高度设置为match_parent引起的。当ListView被隐藏时,它的高度为0,但是它的父容器RelativeLayout的高度仍然为wrap_content。因此,RelativeLayout会显示一个空白区域,大小等于ListView的高度。解决办法是将ListView的高度设置为wrap_content,这样当它被隐藏时,它的高度将为0,RelativeLayout也会跟着缩小。修改代码如下:
```
<ListView
android:id="@+id/poi_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none" />
```
相关问题
帮我写一个安卓layout文件,要求左边是listview,右边是百度地图的mapview
好的,以下是一个简单的安卓layout文件,满足您的要求:
```xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- 左边的ListView -->
<ListView
android:id="@+id/list_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<!-- 右边的MapView -->
<com.baidu.mapapi.map.MapView
android:id="@+id/map_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
```
请注意,您需要在代码中实例化MapView并添加到您的活动中。还需要在清单文件中添加与百度地图相关的权限和服务声明。
在安卓一个Activity中,layout的左边是一个RelativeLayout包裹的listview,右侧是mapview,那么去点击listview的时候,去跳转,然后隐藏这个listview,这时地图右侧会有一个跟listview大小一样的黑屏,我猜测是隐藏listview的时候,mapview又往左边绘制了导致了,这个问题应该怎么解决?
这个问题可能是由于listview隐藏后导致mapview重新布局而导致的。你可以在listview的item点击事件中,先设置listview的可见性为GONE,然后再通过代码设置mapview的宽度为match_parent,这样可以保证在listview隐藏后,mapview会自动填充整个父容器,不会出现黑屏的情况。具体代码如下:
```
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// 隐藏listview
listView.setVisibility(View.GONE);
// 设置mapview的宽度为match_parent
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
mapView.setLayoutParams(params);
}
});
```
阅读全文
相关推荐
















