如果您主要关心的是在布局上添加图像,那么您可以做类似的事情..
步骤(1) 使用RelativeLayout
作为你的父母。
步骤(2)对于您的图像视图,请像这样使用..
<ImageView
android:id="@+id/iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/content_frame"
android:layout_alignParentTop="@+id/content_frame"
android:layout_centerInParent="true"
android:src="@drawable/slider" />
步骤(3) 现在在您的java 类中获取此图像视图的id 并将setOnClickListener 放入其中。
现在,只需单击即可将您定义的代码关闭和打开。确保检查抽屉是否打开,然后关闭抽屉,如果抽屉关闭,则打开抽屉。
除此之外,我建议您使用 ActionBar NavigationDrawer 进行相同的操作..使用起来非常方便。
我在我的一个项目中使用导航抽屉执行了相同的操作..它的工作方式就像魅力一样。
希望能帮助到你..
EDIT
如果您使用 ActionBar NavigationDrawer 或其他任何东西,那么您的首选布局应该如下所示..
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
</FrameLayout>
<ImageView
android:id="@+id/iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/content_frame"
android:layout_alignParentTop="@+id/content_frame"
android:layout_centerInParent="true"
android:src="@drawable/ic_launcher" />
</RelativeLayout>
<ListView
android:id="@+id/listview_drawer_two"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_gravity="right"
android:background="@color/taxi_list_light"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="2dp" />
</android.support.v4.widget.DrawerLayout>
</RelativeLayout>
只需将此布局复制并粘贴到新的 XML 文件中.. 看看它是什么样的..
除此之外,我建议您看看本教程..http://www.androidhive.info/2013/11/android-sliding-menu-using-navigation-drawer/ http://www.androidhive.info/2013/11/android-sliding-menu-using-navigation-drawer/
希望能帮助到你!