DrawerLayout的使用

一:首先是DrawerLayout的布局

<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ListView
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="left"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="#708070"
/>
</android.support.v4.widget.DrawerLayout>
二:其次是向DrawerLayout的ListView中添加item
private final static String[] text = {"123", "213", "23131"};
mListView = (ListView) findViewById(R.id.left_drawer);
mAdapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1, text);
mListView.setAdapter(mAdapter);
三:通过点击控件显示DrawerLayout
mImageView = (ImageView) findViewById(R.id.image);
mImageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mDrawerLayout.openDrawer(mListView);
}
});


posted @ 2016-05-19 14:46  Egg丶牛皮  阅读(188)  评论(0编辑  收藏  举报