最简单的侧滑效果DrawerLayout

来源:互联网 发布:mix软件怎么拼图 编辑:程序博客网 时间:2024/05/18 02:57

主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);}}

好了实现完了.

0 0
原创粉丝点击