DrawerLayout


import android.app.Activity;
import android.os.Bundle;
import android.support.v4.widget.DrawerLayout;
import android.view.Menu;
import android.view.MenuItem;


public class MainActivity extends Activity {
    
    DrawerLayout dl;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }


=======================xml======================




<?xml version="1.0"?>
-<RelativeLayout android:layout_height="match_parent" android:layout_width="match_parent" xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android"> -<android.support.v4.widget.DrawerLayout android:layout_height="match_parent" android:layout_width="match_parent" android:layout_above="@+id/tv" android:id="@+id/dl"> <TextView android:layout_height="match_parent" android:layout_width="match_parent" android:id="@+id/tv_main" android:text="我會顯示在中間"/> <TextView android:layout_height="match_parent" android:layout_width="match_parent" android:id="@+id/tv_left" android:text="我是左側的菜單" android:background="#fff" android:layout_gravity="left"/> <TextView android:layout_height="match_parent" android:layout_width="150dp" android:id="@+id/tv_right" android:text="我是右側的菜單" android:background="#fff" android:layout_gravity="right"/> </android.support.v4.widget.DrawerLayout> <TextView android:layout_height="50dp" android:layout_width="match_parent" android:id="@+id/tv" android:text="低部顯示" android:background="#fff" android:layout_alignParentBottom="true"/> </RelativeLayout>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章