DrawerLayout背景的ListView [英] DrawerLayout background for ListView
问题描述
我有以下我的 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
背景图像与在它上面的黑色认为具有一定的透明度。对于我的iPhone应用程序,它很容易 - 我只是有一个的UIImageView
与的UIView
上,有一个黑色的背景前和.4,一切不透明的作品。
I want to have a background image for my ListView
with a black view on top of it that has some opacity. For my iPhone app it's very easy--I just have a UIImageView
with a UIView
on top that has a black background and opacity of .4 and everything works.
有没有办法在Android中做到这一点?此外,该图像就会从服务器上下载...所以我需要适应的约束也是如此。
Is there a way to do this in Android? Also, this image will be downloaded from the server...so I need to fit that constraint as well.
修改
我试着按下面的第一个答案,并得到了以下错误:
I tried as per the first answer below and got the below error:
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
是 RelativeLayout的
包含的ListView
。
编辑2
原来我所要做的就是从我的Android设备中删除应用程序,然后重建。一切工作!
Turns out all I had to do was delete the app from my android device and then rebuild. Everything else worked!
推荐答案
您只能把两个子视图的 DrawerLayout
,但你可以把<$ C $内C>的ListView 在 RelativeLayout的
。像这样的:
You can only put two child views inside a DrawerLayout
, but you can put the ListView
inside a RelativeLayout
. Like this:
<?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>
**编辑**
这篇关于DrawerLayout背景的ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!