博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Android上实现各种风格的隐藏菜单,比如左右滑动菜单、上下滑动显示隐藏菜单...
阅读量:6541 次
发布时间:2019-06-24

本文共 3610 字,大约阅读时间需要 12 分钟。

Android上的菜单展示风格目前是各式各样的,但用的最多且体验最好的莫过于左右滑动来显示隐藏的菜单

本示例实现了各种方式的菜单展示效果,只有你想不到的
源码:

main.xml

SimplesActivity.java

package net.simonvt.menudrawer.samples;import android.app.ListActivity;import android.content.Intent;import android.os.Bundle;import android.view.View;import android.view.ViewGroup;import android.widget.BaseAdapter;import android.widget.ListView;import android.widget.TextView;import java.util.ArrayList;import java.util.List;public class SamplesActivity extends ListActivity {    private SamplesAdapter mAdapter;    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        mAdapter = new SamplesAdapter();        mAdapter.addSample("Content sample", "Only the content area is dragged.", ContentSample.class);        mAdapter.addSample("ListActivity sample", "Shows how to use the drawer with a ListActivity.",                ListActivitySample.class);        mAdapter.addSample("Window sample", "The entire window is dragged.", WindowSample.class);        mAdapter.addSample("ActionBar overlay sample", "A window sample, where the ActionBar is an overlay",                ActionBarOverlaySample.class);        mAdapter.addSample("Right menu", "The menu is positioned to the right of the content", RightMenuSample.class);        mAdapter.addSample("Top menu", "The menu is positioned above the content", TopMenuSample.class);        mAdapter.addSample("Bottom menu", "The menu is positioned below the content", BottomMenuSample.class);        mAdapter.addSample("Touch Mode", "The menu touch behavior change according to different"                + " content view state (Ex: View Pager)", ViewPagerSample.class);        mAdapter.addSample("Layout xml", "The drawer and its menu and content is defined in XML", LayoutSample.class);        mAdapter.addSample("Static drawer", "The drawer is always visible", StaticDrawerSample.class);        setListAdapter(mAdapter);    }    @Override    protected void onListItemClick(ListView l, View v, int position, long id) {        SampleItem sample = (SampleItem) mAdapter.getItem(position);        Intent i = new Intent(this, sample.mClazz);        startActivity(i);    }    private static class SampleItem {        String mTitle;        String mSummary;        Class mClazz;        public SampleItem(String title, String summary, Class clazz) {            mTitle = title;            mSummary = summary;            mClazz = clazz;        }    }    public class SamplesAdapter extends BaseAdapter {        private List
mSamples = new ArrayList
(); public void addSample(String title, String summary, Class clazz) { mSamples.add(new SampleItem(title, summary, clazz)); } @Override public int getCount() { return mSamples.size(); } @Override public Object getItem(int position) { return mSamples.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { SampleItem sample = (SampleItem) getItem(position); View v = convertView; if (v == null) { v = getLayoutInflater().inflate(R.layout.list_row_sample, parent, false); } ((TextView) v.findViewById(R.id.title)).setText(sample.mTitle); ((TextView) v.findViewById(R.id.summary)).setText(sample.mSummary); return v; } }}

转:

 

转载地址:http://mfsdo.baihongyu.com/

你可能感兴趣的文章
两条新闻 一条今年的 一条去年的
查看>>
关于仙剑Online
查看>>
需求:结合TOGAF做好需求获取工作
查看>>
ASP.NET MVC 3.0学习系列文章—Model in ASP.NET MVC 3.0
查看>>
学习Emacs系列教程(二):导航
查看>>
javascript深入理解js闭包
查看>>
asp.net前台绑定数据和后台绑定数据什么区别
查看>>
LINQ to DataSet实现复杂数据查询
查看>>
匈牙利算法学习 (名词理解 + 简单说明)
查看>>
原型模式
查看>>
c# 线程同步: 详解lock,monitor,同步事件和等待句柄以及mutex
查看>>
Android 程式开发:(廿二)服务 —— 22.1 自定义服务
查看>>
[置顶] ※数据结构※→☆线性表结构(queue)☆============队列 顺序存储结构(queue sequence)(八)...
查看>>
Log4perl 的使用
查看>>
[LeetCode] Contains Duplicate III
查看>>
Linux 系统的单用户模式、修复模式、跨控制台登录在系统修复中的运用
查看>>
《http权威指南》阅读笔记(十)
查看>>
JQuery UI Widget Factory官方Demo
查看>>
Shape comparison language
查看>>
Atlas揭秘 —— 绑定(Binding)
查看>>