主xml代码
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drower_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/fragment_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="主页"
/>
</LinearLayout>
<RelativeLayout
android:id="@+id/menu_left_layout"
android:layout_width="300dp"
android:layout_height="match_parent"
android:layout_gravity="left"
android:background="#ff339933" >
<ListView
android:id="@+id/menu_left_listview"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
主.java代码
package com.lc;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.RelativeLayout;
public class MainActivity extends FragmentActivity {
RelativeLayout mRelativeLayout;
ListView mMenuListViewLeft;
private static final String[] TITLES = { "mytitle", "first", "second",
"third", "fourth", "fifth" };
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
mMenuListViewLeft.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_expandable_list_item_1, TITLES));
}
void init() {
mRelativeLayout = (RelativeLayout) findViewById(R.id.menu_left_layout);
mMenuListViewLeft = (ListView) mRelativeLayout
.findViewById(R.id.menu_left_listview);
}
}
好了实现完了.