首页 文章 精选 留言 我的

精选列表

搜索[ui],共10000篇文章
优秀的个人博客,低调大师

Android UI 备忘:DrawerLayout

DrawerLayout 作者:飞龙 DrawerLayout是android.support.v4中提供的控件,用于实现边栏和侧滑效果。大家在各种 APP 中看到的左侧边栏就是这个控件。 创建 DrawerLayout 最好是界面的顶级布局,否则可能出现触摸时间被屏蔽的问题。它拥有两个子元素,第一个是主内容,第二个是菜单内容。 <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/drawer" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:id="@+id/main_linear" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" /> <ListView android:id="@+id/menu_list" android:layout_width="360dp" android:layout_height="match_parent" android:layout_gravity="left" android:choiceMode="singleChoice" android:divider="@android:color/transparent" android:dividerHeight="0dp" android:background="#111"/> </android.support.v4.widget.DrawerLayout> 主布局和菜单布局都可以是任何东西。这里主布局是空的LinearLayout,菜单布局是ListView。为了使菜单布局宽度合适,我将其设置为360dp。 主内容区的布局代码必须放在侧滑菜单布局的前面, 因为 XML 元素按 z 序(层叠顺序)排列,并且抽屉式导航栏必须位于内容顶部。 菜单布局必须设置layout_gravity属性,它表示侧滑菜单的滑出方向。一共有四个取值: 值 含义 left 左侧滑出 right 右侧滑出 start 如果是从左到右书写的语言,则从左侧滑出,否则从右侧滑出 end 如果是从左到右书写的语言,则从右侧滑出,否则从左侧滑出 如果要在右边放置另一个菜单,只要再添加一个ListView,将layout_gravity设置成相反的方向即可。 效果是这样: 操作 通过手动侧滑可以打开或关闭边栏,触摸主布局可以关闭边栏。 我们也可以编程来打开关闭边栏: void openDrawer(int gravity):打开边栏 void closeDrawer(int gravity):关闭边栏 boolean isDraweropen(int gravity):判断边栏是否打开 参数gravity必须与 XML 中一致,同样有四种选择: Gravity.LEFT Gravity.RIGHT Gravity.START Gravity.END 事件 有的时候,我们需要监听边栏是否打开或关闭。我们需要调用setDrawerListener方法,实现DrawerLayout.DrawerListener作为监听器。我们需要覆盖四个方法。 mDrawerLayout.setDrawerListener(new DrawerListener() { /** * 当抽屉滑动状态改变的时候被调用 * 状态值是STATE_IDLE(闲置-0),STATE_DRAGGING(拖拽-1),STATE_SETTLING(固定-2)中之一。 * 抽屉打开的时候,点击抽屉,drawer的状态就会变成STATE_DRAGGING,然后变成STATE_IDLE */ @Override public void onDrawerStateChanged(int arg0) { } /** * 当抽屉被滑动的时候调用此方法 * arg1 表示 滑动的幅度(0-1) */ @Override public void onDrawerSlide(View arg0, float arg1) { } /** * 当一个抽屉被完全打开的时候被调用 */ @Override public void onDrawerOpened(View arg0) { } /** * 当一个抽屉完全关闭的时候调用此方法 */ @Override public void onDrawerClosed(View arg0) { } }); 但是这样太麻烦了,我们可以继承SimpleDrawerListener,只覆盖所需的方法: mDrawerLayout.setDrawerListener(new SimpleDrawerListener() { @Override public void onDrawerOpened(View arg0) { } @Override public void onDrawerClosed(View arg0) { } });

优秀的个人博客,低调大师

Android UI开发第二十三篇——分享书架UI实现

android中有很多的电子书阅读应用,应用中都仿真了书架的实现,这里也分享一篇读书应用的书架实现: java: public class ShelvesView extends GridView { private Bitmap mShelfBackground; private int mShelfWidth; private int mShelfHeight; private Bitmap mWebLeft; private Bitmap mWebRight; private int mWebRightWidth; public ShelvesView(Context context) { super(context); init(context); } public ShelvesView(Context context, AttributeSet attrs) { super(context, attrs); load(context, attrs, 0); init(context); } public ShelvesView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); load(context, attrs, defStyle); init(context); } private void load(Context context, AttributeSet attrs, int defStyle) { TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ShelvesView, defStyle, 0); final Resources resources = getResources(); final int background = a.getResourceId(R.styleable.ShelvesView_shelfBackground, 0); final Bitmap shelfBackground = BitmapFactory.decodeResource(resources, background); if (shelfBackground != null) { mShelfWidth = shelfBackground.getWidth(); mShelfHeight = shelfBackground.getHeight(); mShelfBackground = shelfBackground; } mWebLeft = BitmapFactory.decodeResource(resources, R.drawable.web_left); final Bitmap webRight = BitmapFactory.decodeResource(resources, R.drawable.web_right); mWebRightWidth = webRight.getWidth(); mWebRight = webRight; a.recycle(); } private void init(Context context) { StateListDrawable drawable = new StateListDrawable(); SpotlightDrawable start = new SpotlightDrawable(context, this); start.disableOffset(); SpotlightDrawable end = new SpotlightDrawable(context, this, R.drawable.spotlight_blue); end.disableOffset(); TransitionDrawable transition = new TransitionDrawable(start, end); drawable.addState(new int[] { android.R.attr.state_pressed }, transition); final SpotlightDrawable normal = new SpotlightDrawable(context, this); drawable.addState(new int[] { }, normal); normal.setParent(drawable); transition.setParent(drawable); setSelector(drawable); setDrawSelectorOnTop(false); } @Override protected void dispatchDraw(Canvas canvas) { final int count = getChildCount(); final int top = count > 0 ? getChildAt(0).getTop() : 0; final int shelfWidth = mShelfWidth; final int shelfHeight = mShelfHeight; final int width = getWidth(); final int height = getHeight(); final Bitmap background = mShelfBackground; for (int x = 0; x < width; x += shelfWidth) { for (int y = top; y < height; y += shelfHeight) { canvas.drawBitmap(background, x, y, null); } } if (count == 0) { canvas.drawBitmap(mWebLeft, 0.0f, top + 1, null); canvas.drawBitmap(mWebRight, width - mWebRightWidth, top + shelfHeight + 1, null); } super.dispatchDraw(canvas); } @Override public void setPressed(boolean pressed) { super.setPressed(pressed); final Drawable current = getSelector().getCurrent(); if (current instanceof TransitionDrawable) { if (pressed) { ((TransitionDrawable) current).startTransition( ViewConfiguration.getLongPressTimeout()); } else { ((TransitionDrawable) current).resetTransition(); } } } } 代码:http://download.csdn.net/detail/xyz_lmn/4698124 本文转自xyz_lmn51CTO博客,原文链接:http://blog.51cto.com/xyzlmn/1230767,如需转载请自行联系原作者

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册