gpt4 book ai didi

android - ListView 的 DrawerLayout 背景

转载 作者:行者123 更新时间:2023-11-30 02:48:15 32 4
gpt4 key购买 nike

我的 DrawerLayout 有以下内容:

<?xml version="1.0" encoding="utf-8"?>

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

<!-- Framelayout to display Fragments -->
<FrameLayout
android:id="@+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />

<!-- Listview to display slider menu -->
<ListView
android:id="@+id/list_slidermenu"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@drawable/background"
android:choiceMode="singleChoice"
android:divider="@color/transparent"
android:dividerHeight="0dp" />

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

我想为我的 ListView 设置一个背景图片,上面有一个不透明的黑色 View 。对于我的 iPhone 应用程序,这非常简单——我只需要一个 UIImageView,顶部有一个 UIView,它具有黑色背景和 .4 的不透明度,一切正常。

有没有办法在 Android 中执行此操作?此外,该图像将从服务器下载...因此我也需要满足该约束。

编辑

我按照下面的第一个答案尝试并得到以下错误:

Process: com.mounzaapp, PID: 17534
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mounzaapp/com.mounzaapp.views.dashboard.DashboardFragmentActivity}: java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.support.v4.widget.DrawerLayout$LayoutParams
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.support.v4.widget.DrawerLayout$LayoutParams
at android.support.v4.widget.DrawerLayout.isDrawerView(DrawerLayout.java:857)
at android.support.v4.widget.DrawerLayout.closeDrawer(DrawerLayout.java:1058)
at com.mounzaapp.views.dashboard.DashboardFragmentActivity.onItemClick(DashboardFragmentActivity.java:257)
at com.mounzaapp.views.dashboard.DashboardFragmentActivity.onCreate(DashboardFragmentActivity.java:148)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)

我在执行以下操作时遇到错误:drawerLayout.closeDrawer(listLayout);listLayout 是包含 ListViewRelativeLayout

编辑 2

事实证明,我所要做的就是从我的 Android 设备上删除该应用程序,然后重新构建。其他一切正常!

最佳答案

您只能将两个 subview 放在 DrawerLayout 中,但您可以将 ListView 放在 RelativeLayout 中。像这样:

<?xml version="1.0" encoding="utf-8"?>

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

<!-- Framelayout to display Fragments -->
<FrameLayout
android:id="@+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />

<!-- RelativeLayout to display slider menu -->
<RelativeLayout
android:id="@+id/drawer_container"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@drawable/background" >

<ListView
android:id="@+id/list_slidermenu"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@drawable/background"
android:choiceMode="singleChoice"
android:divider="@color/transparent"
android:dividerHeight="0dp" />

<!-- Whatever view you want inside the RelativeLayout -->

</RelativeLayout>

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

**** 编辑 ****

Only two child view in DrawerLayout reference

关于android - ListView 的 DrawerLayout 背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24645125/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com