最简单侧滑实现

简单使用DrawerLayout

.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawerlayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

   "@+id/lv"
       android:layout_width="380dp"
       android:layout_height="match_parent"
       android:layout_gravity="start"
       android:background="#4682B4"
       android:divider="#050505"
       android:dividerHeight="2dp"
       >
.support.v4.widget.DrawerLayout>
package com.example.drawer;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

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

public class MainActivity extends Activity {

    private DrawerLayout drawerlayout;
    private ListView lv;
    private List datas;
    private ArrayAdapter adapter;
    private String[] citys={"北京","上海","广州","深圳"};
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        drawerlayout=(DrawerLayout) findViewById(R.id.drawerlayout);
        lv=(ListView) findViewById(R.id.lv);
        datas=new ArrayList();
        datas.addAll(Arrays.asList(citys));
        adapter=new ArrayAdapter(this, android.R.layout.simple_expandable_list_item_1, datas);
        lv.setAdapter(adapter);
    }
}

Eclipse源码下载

你可能感兴趣的:(Android)