标签:
抽屉式布局
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/dl"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<!--如果抽屉没有打开 会显示线性布局 -->
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</LinearLayout>
<!-- 左面可以滑出来一个抽屉 -->
<!--
<RelativeLayout
android:layout_gravity="left"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff0000">
</RelativeLayout> -->
<RelativeLayout
android:layout_gravity="right"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffff00">
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
//java类
package com.example.dawerlayout;
import android.os.Bundle;
import android.app.Activity;
import android.support.v4.widget.DrawerLayout;
import android.support.v4.widget.DrawerLayout.DrawerListener;
import android.view.Gravity;
import android.view.Menu;
import android.view.View;
public class MainActivity extends Activity {
DrawerLayout drawerLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
drawerLayout=(DrawerLayout) findViewById(R.id.dl);
drawerLayout.openDrawer(Gravity.RIGHT);// 右边打开抽屉
drawerLayout.setDrawerListener(new DrawerListener() {
@Override
public void onDrawerStateChanged(int arg0) {
}
@Override
public void onDrawerSlide(View arg0, float arg1) {
}
@Override
public void onDrawerOpened(View arg0) {
}
@Override
public void onDrawerClosed(View arg0) {
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
标签:
原文地址:http://www.cnblogs.com/heartstong/p/4682968.html