android防谷歌滑动效果,谷歌是如何做到这一点的?在Android应用程序中滑动ActionBar...

事实上,有一种方法可以做到这一点。即使没有实施自己的ActionBar。

看看hierachyviewer吧!(位于工具目录中)

还有的DecorView,并且LinearLayout作为一个孩子。这LinearLayout包含ActionBar其他内容和其他内容。所以,你可以简单地应用一些FrameLayout.LayoutParams,LinearLayout并以这种方式在左侧获得一些空间。然后,您可以使用菜单ListView填充此空间,并使用FrameLayout覆盖其他内容,当单击它时,折叠菜单。所以,这里有一些代码:

首先,折叠/扩展类(SlideMenu.java):package your.cool.app;import android.app.Activity;import android.content.Context;import android.content.Intent;import android.graphics.Rect;import android.util.Log;import android.view.LayoutInflater;import android.view.View;import android.view.View.OnClickListener;import android.view.ViewGroup;import android.view.Window;import android.view.animation.TranslateAnimation;import android.widget.AdapterView;import android.widget.AdapterView.OnItemClickListener;import android.widget.ArrayAdapter;import android.widget.FrameLayout;import android.widget.ImageView;import android.widget.LinearLayout;import android.widget.ListView;import android.widget.TextView;public class SlideMenu {//just a simple adapterpublic static class SlideMenuAdapter extends ArrayAdapter {

Activity act;

SlideMenu.SlideMenuAdapter.MenuDesc[] items;

class MenuItem {

public TextView label;

public ImageView icon;

}

static class MenuDesc {

public int icon;

public String label;

}

public SlideMenuAdapter(Activity act, SlideMenu.SlideMenuAdapter.MenuDesc[] items) {

super(act, R.id.menu_label, items);

this.act = act;

this.items = items;

}

@Override

public View getView(int position, View convertView, ViewGroup parent) {

View rowView = convertView;

if (rowView == null) {

LayoutInflater inflater = act.getLayoutInflater();

rowView = inflater.inflate(R.layout.menu_listitem, null);

MenuItem viewHolder = new MenuItem();

viewHolder.label = (TextView) rowView.findViewById(R.id.menu_label);

viewHolder.icon = (ImageView) rowView.findViewById(R.id.menu_icon);

rowView.setTag(viewHolder);

}

MenuItem holder = (MenuItem) rowView.getTag();

String s = items[position].label;

holder.label.setText(s);

holder.icon.setImageResource(items[position].icon);

return rowView;

}}private static boolean menuShown = false;private static View menu;private static LinearLayout content;private static FrameLayout parent;private static int menuSize;private static int statusHeight = 0;private Activity act;SlideMenu(Activity act) {

this.act = act;}//call this in your onCreate() for screen rotationpublic void checkEnabled() {

if(menuShown)

this.show(false);}public void show() {//get the height of the status bar

if(statusHeight == 0) {

Rect rectgle = new Rect();

Window window = act.getWindow();

window.getDecorView().getWindowVisibleDisplayFrame(rectgle);

statusHeight = rectgle.top;

}

this.show(true);}public void show(boolean animate) {

menuSize = Functions.dpToPx(250, act);

content = ((LinearLayout) act.findViewById(android.R.id.content).getParent());

FrameLayout.LayoutParams parm = (FrameLayout.LayoutParams) content.getLayoutParams();

parm.setMargins(menuSize, 0, -menuSize, 0);

content.setLayoutParams(parm);//animation for smooth slide-out

TranslateAnimation ta = new TranslateAnimation(-menuSize, 0, 0, 0);

ta.setDuration(500);

if(animate)

content.startAnimation(ta);

parent = (FrameLayout) content.getParent();

LayoutInflater inflater = (LayoutInflater) act.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

menu = inflater.inflate(R.layout.menu, null);

FrameLayout.LayoutParams lays = new FrameLayout.LayoutParams(-1, -1, 3);

lays.setMargins(0,statusHeight, 0, 0);

menu.setLayoutParams(lays);

parent.addView(menu);

ListView list = (ListView) act.findViewById(R.id.menu_listview);

list.setOnItemClickListener(new OnItemClickListener() {

@Override

public void onItemClick(AdapterView> parent, View view, int position, long id) {

//handle your menu-click

}

});

if(animate)

menu.startAnimation(ta);

menu.findViewById(R.id.overlay).setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

SlideMenu.this.hide();

}

});

Functions.enableDisableViewGroup((LinearLayout) parent.findViewById(android.R.id.content).getParent(), false);

((ExtendedViewPager) act.findViewById(R.id.viewpager)).setPagingEnabled(false);

((ExtendedPagerTabStrip) act.findViewById(R.id.viewpager_tabs)).setNavEnabled(false);

menuShown = true;

this.fill();}public void fill() {

ListView list = (ListView) act.findViewById(R.id.menu_listview);

SlideMenuAdapter.MenuDesc[] items = new SlideMenuAdapter.MenuDesc[5];

//fill the menu-items here

SlideMenuAdapter adap = new SlideMenuAdapter(act, items);

list.setAdapter(adap);}public void hide() {

TranslateAnimation ta = new TranslateAnimation(0, -menuSize, 0, 0);

ta.setDuration(500);

menu.startAnimation(ta);

parent.removeView(menu);

TranslateAnimation tra = new TranslateAnimation(menuSize, 0, 0, 0);

tra.setDuration(500);

content.startAnimation(tra);

FrameLayout.LayoutParams parm = (FrameLayout.LayoutParams) content.getLayoutParams();

parm.setMargins(0, 0, 0, 0);

content.setLayoutParams(parm);

Functions.enableDisableViewGroup((LinearLayout) parent.findViewById(android.R.id.content).getParent(), true);

((ExtendedViewPager) act.findViewById(R.id.viewpager)).setPagingEnabled(true);

((ExtendedPagerTabStrip) act.findViewById(R.id.viewpager_tabs)).setNavEnabled(true);

menuShown = false;}}

一些帮助方法(对我来说,在静态Functions.java中):public static int dpToPx(int dp, Context ctx) {

Resources r = ctx.getResources();

return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, r.getDisplayMetrics());}//originally: http://stackoverflow.com/questions/5418510/disable-the-touch-events-for-all-the-views//modified for the needs herepublic static void enableDisableViewGroup(ViewGroup viewGroup, boolean enabled) {

int childCount = viewGroup.getChildCount();

for (int i = 0; i 

View view = viewGroup.getChildAt(i);

if(view.isFocusable())

view.setEnabled(enabled);

if (view instanceof ViewGroup) {

enableDisableViewGroup((ViewGroup) view, enabled);

} else if (view instanceof ListView) {

if(view.isFocusable())

view.setEnabled(enabled);

ListView listView = (ListView) view;

int listChildCount = listView.getChildCount();

for (int j = 0; j 

if(view.isFocusable())

listView.getChildAt(j).setEnabled(false);

}

}

}

}

然后,布局:

菜单布局(res / layout / menu.xml)

android:layout_width="fill_parent"

android:layout_height="fill_parent" >

android:orientation="vertical"

android:layout_height="fill_parent"

android:layout_width="250dip"

android:background="@color/darkblack">

android:id="@+id/menu_listview"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:divider="@color/dividerblack"

android:dividerHeight="2dip"  />

android:id="@+id/overlay"

android:layout_width="match_parent"

android:layout_height="match_parent" >

listitems的布局(res / layout / menu_listitem.xml):

android:id="@+id/menu_icon"

android:layout_width="30dp"

android:layout_height="30dp"

android:layout_marginRight="5dip"

android:layout_marginLeft="10dip"

android:layout_marginTop="10dip"

android:layout_marginBottom="10dip" />

android:id="@+id/menu_label"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:textColor="@color/white"

android:textSize="24dp"

android:layout_marginTop="10dip"

android:layout_marginBottom="10dip" />

如何使用它:

在你的onCreate():private SlideMenu slidemenu;@Overridepublic void onCreate(Bundle savedInstanceState) {

//your onCreate code

slidemenu = new SlideMenu(this);

slidemenu.checkEnabled();}

在ActionBar homebutton的处理程序中:slidemenu.show();

而已!

现在,它的一些屏幕截图:

据我所知,它正在发挥作用。如果您遇到任何问题或我的解释不明确,请与我联系!

编辑:ExtendedViewPager&ExtendedPagerStrip:

ExtendedViewPager:package your.cool.app;//source: http://blog.svpino.com/2011/08/disabling-pagingswiping-on-android.htmlimport android.content.Context;import android.support.v4.view.ViewPager;import android.util.AttributeSet;import android.view.MotionEvent;public class ExtendedViewPager extends ViewPager {private boolean enabled;public ExtendedViewPager(Context context, AttributeSet attrs) {

super(context, attrs);

this.enabled = true;}@Overridepublic boolean onTouchEvent(MotionEvent event) {

if (this.enabled) {

return super.onTouchEvent(event);

}

return false;}@Overridepublic boolean onInterceptTouchEvent(MotionEvent event) {

if (this.enabled) {

return super.onInterceptTouchEvent(event);

}

return false;}public void setPagingEnabled(boolean enabled) {

this.enabled = enabled;}}

ExtendedPagerTabStrip:package your.cool.app;//source: http://blog.svpino.com/2011/08/disabling-pagingswiping-on-android.htmlimport android.content.Context;import android.support.v4.view.PagerTabStrip;import android.util.AttributeSet;import android.view.MotionEvent;public class ExtendedPagerTabStrip extends PagerTabStrip {private boolean enabled;public ExtendedPagerTabStrip(Context context, AttributeSet attrs) {

super(context, attrs);

this.enabled = true;}@Overridepublic boolean onTouchEvent(MotionEvent event) {

if (this.enabled) {

return super.onTouchEvent(event);

}

return false;}@Overridepublic boolean onInterceptTouchEvent(MotionEvent event) {

if (this.enabled) {

return super.onInterceptTouchEvent(event);

}

return false;}public void setNavEnabled(boolean enabled) {

this.enabled = enabled;}}

我将它SlideMenu用于一个ViewPager带有PagerTabStripfor,如Talk,Market等标签的Activity 。你不能以一种简单的方式禁用这些视图,所以上面的两个类只是扩展它们以onTouch在禁用时停止事件。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/460041.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

thinkphp框架使用心得

接触的第一个PHP框架就是TP,在使用的了一段时间后就放弃了,说实话TP的弊端挺多,之后又接触laravel框架,慢慢的就爱上laravel这个框架了。这段时间由于公司的原因,又不得不使用thinkphp框架,在这里分享下使用心得。 TP框…

计算本年 本月 本周的起始日期

html: <table><tr><td align"right" width"120px"> 销售时间区间:</td><td><select id"ddlChoiceDate" name"ddlChoiceDate" runat"server" onchange"SelectChange(this.value);&quo…

Android查看真机布局,android-外部存储

外部存储&#xff0c;个人理解是在app作用域之外存储&#xff0c;就是数据没有和app做关联&#xff0c;app卸载后&#xff0c;它依旧存在而不再是之前手机本身存储空间和sd卡的区别&#xff0c;现在安卓手机已经不携带可拆卸的SD卡androidManifest.xml 需要写入读写权限简单布局…

用自己的ID在appstore中更新app-黑苹果之路

由于之前套用了别人的镜像&#xff0c;在appstore中更新XCode时总要输别人id的密码&#xff0c;id还不能改。网上有的说要把XCode删掉&#xff0c;然后再用自己的ID更新&#xff0c;找到另外一个方法&#xff0c;更简单&#xff1a; 1.打开引用程序目录 2.找到Xcode&#xff0c…

如何打开pr_debug调试信息

转载&#xff1a;http://blog.csdn.net/helloanthea/article/details/25330809 以DMA的调试为例&#xff0c;先来看看一个pr_debug函数调用 pr_debug("%s: %s (%s)\n",__func__,chan ? "success" : "fail",chan ? dma_chan_name(chan) : NULL)…

android国籍组件,android组件化之路

问题&#xff1a;实际业务变化快&#xff0c;而工程内各个功能模块耦合度太高&#xff0c;不能对功能模块进行快速方便地拆分或组装。团队共同开发中&#xff0c;可能一个文件同时被多人修改&#xff0c;导致每次更新提交代码都需要消耗大量时间去merge代码。每次修改&#xff…

UNIX环境编程学习笔记(21)——进程管理之获取进程终止状态的 wait 和 waitpid 函数...

lienhua342014-10-12 当一个进程正常或者异常终止时,内核就向其父进程发送 SIGCHLD信号。父进程可以选择忽略该信号,或者提供一个该信号发生时即被调用的函数(信号处理程序)。对于这种信号的系统默认动作是忽略它。 在文档“进程控制三部曲”中,我们讲的第三部曲是使用 wait 函…

poj2750 PottedFlower(线段树的环状操作)

题目&#xff1a;Potted Flower 大意&#xff1a;该你一个换环&#xff0c;求环上的最大连续的和&#xff08;如果最大和包含所有数&#xff0c;要求减去最小的一个&#xff09;。 思路&#xff1a;这道题的思路并不难&#xff0c;需要在线段树里维护区间的最大和&#xff0c…

android代码导入有错误,android新项目导入后进行编译出现cmake错误

问题描述使用as加载并且gradle sync 提示&#xff1a;SIMPLE:error configure同时使用make project提示问题出现的环境背景及自己尝试过哪些方法已经尝试更换过ndk 调整target brinary 然后完全clean project等操作相关代码// 请把代码文本粘贴到下方(请勿用图片代替代码)使用g…

简单排序算法设计(Java)

总共有八种排序算法&#xff0c;还是慢慢看吧 1、简单排序算法 简单排序算法就是设置标兵&#xff0c;逐个比较数&#xff0c;然后查找插入位置&#xff0c;插入 public static void p(int[] a){for(int i0;i<a.length;i){System.out.print(a[i]" ");}}public sta…

cocos2d-x坐标系

在cocos2d-x在&#xff0c;有几种不同的坐标系。因为有好几个坐标系着一定的差异&#xff0c;他们需要明白&#xff0c;能力更精确的绘制各种图形画面上。 1.屏幕坐标系 只windows通过绘制图形上基本都知道。相应的坐标系统&#xff1a;原点在左上角。向右是x轴正方向&#xff…

android收入管理系统,毕业设计(论文)-基于Android系统的家庭理财通软件的设计——收入管理模块.docx...

PAGE河北农业大学信息学院本科毕业论文题 目&#xff1a;基于Android系统的家庭理财通软件的设计——收入管理模块学 院&#xff1a; 信息科学与技术学院专业班级&#xff1a; 计算机科学与技术0902班学 号&#xff1a;二O一三 年 五 月 二十八 日摘 要基于安卓系统的家庭理财通…

BZOJ1652 [Usaco2006 Feb]Treats for the Cows

蒟蒻许久没做题了&#xff0c;然后连动规方程都写不出了。 参照iwtwiioi大神&#xff0c;这样表示区间貌似更方便。 令f[i, j]表示i到j还没卖出去&#xff0c;则 f[i, j] max(f[i 1, j] v[i] * T, f[i, j - 1] v[j] * T) &#xff08;←这样用推的方式更好想一点。。&#…

android系统提供了url通信,Android两种HTTP通信,HttpURLConnection和HttpClient

Android系统中主要提供了两种方式来进行HTTP通信&#xff0c;HttpURLConnection和HttpClient&#xff0c;几乎在任何项目的代码中我们都能看到这两个类的身影&#xff0c;使用率非常高。不过HttpURLConnection和HttpClient的用法还是稍微有些复杂的&#xff0c;如果不进行适当封…

ECSHOP 订单状态 记录

记录订单状态 order_status /* 订单状态 */ define(‘OS_UNCONFIRMED’, 0); // 未确认 define(‘OS_CONFIRMED’, 1); // 已确认 define(‘OS_CANCELED’, 2); // 已取消 define(‘OS_INVALID’, 3); // 无效 define(‘…

git+jekyll部署备忘

github&#xff0c;会自动帮忙编译jekyll编写的文件&#xff0c;只要将文件放到gh-pages分支 (或者使用官方教程的二级域名方式&#xff0c;项目名字&#xff0c;可以随便起&#xff0c;官网的例子是 用户名.github.com 作为项目名字&#xff0c;可以使用 用户名.github.com …

buidulbs android.jar,在将AS项目迁移到IDEA时,无法将com.android.bui...

我需要从Android Studio迁移到IntelliJ IDEA,因为我需要在Java中进行其他一些非Android的工作.我从git克隆了我的项目,并将其导入到IDEA中.但是,我在此过程中遇到了Gradle错误.我已经搜索过,但是找不到解决我的错误的答案.这是事件日志03:39:42 PM All files are up-to-date03:…

[华为机试练习题]60.水仙花数

题目 描述: 水仙花数又称阿姆斯特朗数。 水仙花数是指一个n 位数( n≥3 )&#xff0c;它的每个位上的数字的n 次幂之和等于它本身。&#xff08;例如&#xff1a;1^3 5^3 3^3 153&#xff09; 求输入的数字是否为水仙花数练习阶段: 初级 代码 /*-------------------------…

fscanf的返回值未成功输入的元素个数 .xml

test.txt 中保存的为&#xff1a;12345程序int i,j,k; FILE *fpfopen("e://test.txt","r"); if (fpNULL) { //return FALSE; } while (!feof(fp)) { jfscanf(fp,"%d%d",&i,&k); cout<<i<</t<<k<</t<…

Chrome英文版离线安装包下载

在原来在线安装地址后面加上 ?standalone1 即可 https://www.google.com/intl/en/chrome/browser/desktop/index.html?standalone1