透明Listview在谷歌地图android

时间:2015-08-04 11:58:30

标签: android google-maps listview android-listview

在我的应用程序中,我需要在谷歌地图上创建一个透明的列表视图。我正在使用切换按钮来打开和关闭listview。当列表视图可见时,它应该是透明的,以便谷歌地图应该是可见/半可见的。

这部分有三种布局。 1. custom_cluster_mapview.xml 2. bottomlayout.xml 3. map_list_view_row

  1. custom_cluster_mapview.xml

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    xmlns:materialdesign="http://schemas.android.com/apk/com.gc.materialdesign"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".map.MapView" >
    
    <LinearLayout
        android:id="@+id/myLinearLayout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    
        <LinearLayout
            android:id="@+id/mapLayout"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1" >
    
            <fragment
                android:id="@+id/mycustomemap"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                class="com.google.android.gms.maps.SupportMapFragment" />
        </LinearLayout>
    
        <include layout="@layout/bottomlayout" />
    
    
    
    
    </LinearLayout>
    
    </RelativeLayout>
    
  2. bottomlayout.xml

       <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
    
        android:id="@+id/outerLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:weightSum="2"
        android:orientation="vertical"
        >
    
    
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                >
            <ToggleButton
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:background="@drawable/up_arrow"
                android:textOff=""
                android:textOn=""
                android:id="@+id/toggleButtonListView"
                android:layout_gravity="center_horizontal" />
            </LinearLayout>
    
        <LinearLayout
            android:id="@+id/mapListViewSlider"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:visibility="gone"
            android:layout_weight="1.95"
            android:orientation="vertical">
    
    
            <CheckBox
                android:id="@+id/sort_distance"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Sort By Distance"/>
            <ListView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:dividerHeight="5dp"
                android:divider="@color/red"
                android:id="@+id/map_listview"/>
            </LinearLayout>
    
    </LinearLayout>
    
  3. 第3。 map_list_view_row.xml

        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingTop="10dp"
        android:paddingBottom="12dp">
    
    
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_marginLeft="10dp"
            android:weightSum="4"
            android:id="@+id/linearLayout">
            <RelativeLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1">
                <TextView
                    android:id="@+id/map_list_view_tv1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:text="@string/label_name" />
    
                <TextView
                    android:id="@+id/map_list_view_name"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_toRightOf="@id/map_list_view_tv1"
                    android:text="abcde"/>
            </RelativeLayout>
    
            <RelativeLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1">
    
                <TextView
                    android:id="@+id/map_list_view_tv2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/label_category" />
                <TextView
                    android:id="@+id/map_list_view_category"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_toRightOf="@+id/map_list_view_tv2"
                    android:text="abcde" />
            </RelativeLayout>
    
            <RelativeLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1">
                <TextView
                    android:id="@+id/map_list_view_tv3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/label_location" />
                <TextView
                    android:id="@+id/map_list_view_location"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_toRightOf="@+id/map_list_view_tv3"
                    android:text="abcde" />
            </RelativeLayout>
    
            <RelativeLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1">
    
                <TextView
                    android:id="@+id/map_list_view_tv4"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true"
                    android:layout_marginBottom="10dp"
                    android:text="@string/label_distance" />
    
                <TextView
                    android:id="@+id/map_list_view_distance"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_toRightOf="@+id/map_list_view_tv4"
                    android:text="abcde" />
    
            </RelativeLayout>
        </LinearLayout>
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/map_list_view_imageView"
            android:background="@drawable/med"
            android:layout_marginTop="4dp"
            android:layout_marginRight="16dp"
            android:layout_alignParentRight="true"/>
    
    </RelativeLayout>
    

    以下是加载地图时的图片 http://i.stack.imgur.com/GtizG.png

    屏幕底部有向上箭头按钮。我想让这个透明的背景。这样只有箭头才能看到没有任何背景。当我点击箭头列表时,会显示。如下所示

    http://i.stack.imgur.com/CUFZz.png

    如何使listView透明,以便谷歌地图可见/半可见。

    提前致谢。

3 个答案:

答案 0 :(得分:1)

将此行置于相对布局中,而不是“线性布局”

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

并将此布局中的所有颜色设置为半透明。

答案 1 :(得分:1)

只需在列表视图中添加此属性

即可
 android:background="@android:color/transparent" 
 android:cacheColorHint="@android:color/transparent"

Reference

答案 2 :(得分:0)

ListView默认情况下具有透明/半透明背景,因此所有默认的Android小部件都是如此。这意味着当ListView重绘其子项时,它必须将子项与窗口的背景混合。

要解决您的问题,您所要做的就是禁用缓存颜色提示优化,如果您使用非纯色背景,或将提示设置为适当的纯色值。这可以是代码或最好是XML。

XML:

android:cacheColorHint="#0000"
android:background="@android:color/transparent"

代码:

listView.setCacheColorHint(Color.TRANSPARENT);