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);
}
});
上一篇:Python中if __name__ == "__main__"详解


下一篇:数仓--Hive-面试之简述UDF/UDAF/UDTF是什么,各自解决问题及应用场景