android 中DrawerLayout实现抽屉,Android-Camera内存问题剖析

package com.example.drawerlayout;

import java.util.ArrayList;

import android.os.Bundle;

import android.app.ActionBar;

im

《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》

浏览器打开:qq.cn.hn/FTe 免费领取

port android.app.Activity;

import android.content.Context;

import android.content.res.Configuration;

import android.support.v4.app.ActionBarDrawerToggle;

import android.support.v4.widget.DrawerLayout;

import android.support.v4.widget.DrawerLayout.DrawerListener;

import android.view.LayoutInflater;

import android.view.Menu;

import android.view.MenuItem;

import android.view.View;

import android.view.View.OnClickListener;

import android.view.ViewGroup;

import android.widget.AdapterView;

import android.widget.AdapterView.OnItemClickListener;

import android.widget.ArrayAdapter;

import android.widget.BaseAdapter;

import android.widget.ImageView;

import android.widget.ListView;

import android.widget.SlidingDrawer.OnDrawerOpenListener;

import android.widget.TextView;

import android.widget.Toast;

public class MainActivity extends Activity {

private String string[] = new String[12];

private ArrayList list = new ArrayList();

private ActionBarDrawerToggle toggle;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

DrawerLayout layout = (DrawerLayout) findViewById(R.id.drawer);

ImageView imageView = (ImageView) findViewById(R.id.img);

final ListView listView = (ListView) findViewById(R.id.list);

//获取手机的菜单栏

final ActionBar actionBar = getActionBar();

actionBar.setTitle(“主界面”);

//标题栏的home可以点击

actionBar.setIcon(android.R.drawable.btn_radio);

actionBar.setDisplayHomeAsUpEnabled(true);

actionBar.setHomeButtonEnabled(true);

toggle = new ActionBarDrawerToggle(MainActivity.this,

layout, android.R.drawable.btn_star,

android.R.drawable.btn_star_big_on,

android.R.drawable.btn_star_big_off){

@Override

public void onDrawerClosed(View drawerView) {

super.onDrawerClosed(drawerView);

actionBar.setTitle(“主界面”);

}

@Override

public void onDrawerOpened(View drawerView) {

super.onDrawerOpened(drawerView);

actionBar.setTitle(“菜单界面”);

}

};

//打开或者关闭时的状态

toggle.syncState();

layout.setDrawerListener(toggle);

for (int i = 0; i < string.length; i++) {

list.add(“想发火” + i);

}

if (list != null && list.size() > 0) {

MyAdapter adapter = new MyAdapter(MainActivity.this, list);

listView.setAdapter(adapter);

}

listView.setOnItemClickListener(new OnItemClickListener() {

@Override

public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,

long arg3) {

Toast.makeText(MainActivity.this, “我想打死你,***”,

Toast.LENGTH_SHORT).show();

}

});

}

@Override

public boolean onOptionsItemSelected(MenuItem item) {

return toggle.onOptionsItemSelected(item)||super.onOptionsItemSelected(item);

}

@Override

public void onConfigurationChanged(Configuration newConfig) {

super.onConfigurationChanged(newConfig);

toggle.onConfigurationChanged(newConfig);

}

}

class MyAdapter extends BaseAdapter {

private Context context;

private ArrayList list;

public MyAdapter(Context context, ArrayList list) {

this.context = context;

this.list = list;

}

@Override

public int getCount() {

return list.size();

}

@Override

public Object getItem(int arg0) {

return null;

}

@Override

public long getItemId(int arg0) {

return arg0;

}

@Override

public View getView(int arg0, View arg1, ViewGroup arg2) {

ViewHolder vHolder;

if (arg1 == null) {

arg1 = LayoutInflater.from(context).inflate(R.layout.listview_item,

null);

vHolder = new ViewHolder();

vHolder.textView = (TextView) arg1.findViewById(R.id.list_text);

arg1.setTag(vHolder);

上一篇:接口


下一篇:IDEA 插件开发笔记