【问题标题】:Transparent Listview over google Map androidgoogle Map android上的透明Listview
【发布时间】:2015-08-04 11:58:29
【问题描述】:

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

这部分有三种布局。 1.custom_cluster_mapview.xml 2.底部布局.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. 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

屏幕底部有向上箭头按钮。我想让那个透明的背景。所以只有箭头是可见的,没有任何背景。当我单击箭头时,会显示 listView。如下所示

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

如何让listView透明化,让google地图可见/半可见。

提前致谢。

【问题讨论】:

  • 我不确定,但你可以试试:android:background="@null"
  • 请将其添加到列表视图本身
  • Bhavesh N 给出了解决方案。它正在工作。\
  • 太棒了 :D 会在我需要时记录下来

标签: android google-maps listview android-listview


【解决方案1】:

将此行放在相对布局中,而不是在线性布局中

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

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

【讨论】:

  • 底部布局半透明?我已经尝试了所有的东西。我使用 android:theme="@android:style/Theme.Translucent" 使活动变得透明。但什么也没发生。
  • 非常感谢。有效。你能解释一下吗?再来一次。谢谢。
  • Bhavesh N 你能解释一下它为什么有效吗?出了什么问题?
  • 您已将包含标签放入线性布局中,因此它始终显示在地图下方,因此当您单击箭头时,整个地图都会向上移动。
【解决方案2】:

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

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

Reference

【讨论】:

    【解决方案3】:

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

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

    XML:

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

    代码:

    listView.setCacheColorHint(Color.TRANSPARENT);
    

    【讨论】:

    • 福尔摩斯。我也尝试了编辑版本。 bhavesh N 解决方案工作正常。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多