【问题标题】:Drawer layout listView transparent background抽屉布局listView透明背景
【发布时间】:2023-03-02 22:58:02
【问题描述】:

我正在尝试将抽屉布局内的列表视图的背景设置为像谷歌的相机应用程序一样透明。

每当我将列表视图的背景设置为透明时,它的项目就会消失

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

<ListView
    android:id="@+id/activity_main_navigation_list"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:choiceMode="singleChoice"
    android:background="@android:color/transparent"
    android:divider="@android:color/transparent"
    android:dividerHeight="0dp" />

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

我尝试将其设置为透明图像,但它无法正常工作,或者它无法使用添加到背景颜色的任何透明度。

这行得通:

        android:background="#232321"

这不是

        android:background="#fb232321"

知道如何解决这个问题

【问题讨论】:

  • 嗨,请在此处添加 listview 行 xml 文件
  • 你试过设置列表项的背景吗?
  • 列表项与此问题无关,每当我将列表视图的背景设置为任何东西而不是不透明颜色时,它都会独立于其项目或其父项而消失。

标签: android android-listview


【解决方案1】:

尝试在 DrawerLayout 视图上而不是在 listView 上使用 android:background="@color/transparent"。此外,您可以在 ListView 的 childView 上使用背景透明

【讨论】:

  • 列表项与此问题无关,每当我将列表视图的背景设置为任何东西而不是不透明颜色时,它都会独立于其项目或其父项而消失。
  • 您是否尝试过从 listView 属性中完全移除背景?
【解决方案2】:

所以我通过使用 Relativelayout 包装列表视图解决了我的问题,它也适用于其他布局。

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

<FrameLayout
    android:id="@+id/activity_main_frame_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="@android:color/transparent"
    android:focusableInTouchMode="true">

    <ListView
        android:id="@+id/activity_main_navigation_list"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:choiceMode="singleChoice"
        android:clickable="true"
        android:divider="@android:color/transparent"
        android:dividerHeight="1dp"
        android:focusable="true" />
</RelativeLayout> 

【讨论】:

    【解决方案3】:

    使用#00000000 表示黑色透明度

    【讨论】:

    • 这样不行,我已经为我的问题添加了解决方案
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-24
    • 1970-01-01
    • 2012-11-01
    • 2020-03-18
    相关资源
    最近更新 更多