首页 文章 精选 留言 我的

精选列表

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

[Android] Android开发优化之——对界面UI的优化(1)

在Android应用开发过程中,屏幕上控件的布局代码和程序的逻辑代码通常是分开的。界面的布局代码是放在一个独立的xml文件中的,这个文件里面是树型组织的,控制着页面的布局。通常,在这个页面中会用到很多控件,控件会用到很多的资源。Android系统本身有很多的资源,包括各种各样的字符串、图片、动画、样式和布局等等,这些都可以在应用程序中直接使用。这样做的好处很多,既可以减少内存的使用,又可以减少部分工作量,也可以缩减程序安装包的大小。 下面从几个方面来介绍如何利用系统资源。 1)利用系统定义的id 比如我们有一个定义ListView的xml文件,一般的,我们会写类似下面的代码片段。 <ListView android:id="@+id/mylist" android:layout_width="fill_parent" android:layout_height="fill_parent"/> 这里我们定义了一个ListView,定义它的id是"@+id/mylist"。实际上,如果没有特别的需求,就可以利用系统定义的id,类似下面的样子。 <ListView android:id="@android:id/list" android:layout_width="fill_parent" android:layout_height="fill_parent"/> 在xml文件中引用系统的id,只需要加上“@android:”前缀即可。如果是在Java代码中使用系统资源,和使用自己的资源基本上是一样的。不同的是,需要使用android.R类来使用系统的资源,而不是使用应用程序指定的R类。这里如果要获取ListView可以使用android.R.id.list来获取。 2)利用系统的图片资源 假设我们在应用程序中定义了一个menu,xml文件如下。 <?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/menu_attachment" android:title="附件" android:icon="@android:drawable/ic_menu_attachment" /> </menu> 其中代码片段android:icon="@android:drawable/ic_menu_attachment"本来是想引用系统中已有的Menu里的“附件”的图标。但是在Build工程以后,发现出现了错误。提示信息如下: error: Error: Resource is not public. (at 'icon' with value '@android:drawable/ic_menu_attachment'). 从错误的提示信息大概可以看出,由于该资源没有被公开,所以无法在我们的应用中直接引用。既然这样的话,我们就可以在Android SDK中找到相应的图片资源,直接拷贝到我们的工程目录中,然后使用类似android:icon="@drawable/ic_menu_attachment"的代码片段进行引用。 这样做的好处,一个是美工不需要重复的做一份已有的图片了,可以节约不少工时;另一个是能保证我们的应用程序的风格与系统一致。 经验分享: Android中没有公开的资源,在xml中直接引用会报错。除了去找到对应资源并拷贝到我们自己的应用目录下使用以外,我们还可以将引用“@android”改成“@*android”解决。比如上面引用的附件图标,可以修改成下面的代码。 android:icon="@*android:drawable/ic_menu_attachment" 修改后,再次Build工程,就不会报错了。 3)利用系统的字符串资源 假设我们要实现一个Dialog,Dialog上面有“确定”和“取消”按钮。就可以使用下面的代码直接使用Android系统自带的字符串。 <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content"> <Button android:id="@+id/yes" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1.0" android:text="@android:string/yes"/> <Button android:id="@+id/no" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1.0" android:text="@android:string/no"/> </LinearLayout> 如果使用系统的字符串,默认就已经支持多语言环境了。如上述代码,直接使用了@android:string/yes和@android:string/no,在简体中文环境下会显示“确定”和“取消”,在英文环境下会显示“OK”和“Cancel”。 4)利用系统的Style 假设布局文件中有一个TextView,用来显示窗口的标题,使用中等大小字体。可以使用下面的代码片段来定义TextView的Style。 <TextView android:id="@+id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" /> 其中android:textAppearance="?android:attr/textAppearanceMedium"就是使用系统的style。需要注意的是,使用系统的style,需要在想要使用的资源前面加“?android:”作为前缀,而不是“@android:”。 5)利用系统的颜色定义 除了上述的各种系统资源以外,还可以使用系统定义好的颜色。在项目中最常用的,就是透明色的使用。代码片段如下。 android:background ="@android:color/transparent" 经验分享: Android系统本身有很多资源在应用中都可以直接使用,具体的,可以进入android-sdk的相应文件夹中去查看。例如:可以进入$android-sdk$\platforms\android-8\data\res,里面的系统资源就一览无余了。 开发者需要花一些时间去熟悉这些资源,特别是图片资源和各种Style资源,这样在开发过程中,能够想到有相关资源并且直接拿来使用。 本文转自农夫山泉别墅博客园博客,原文链接:http://www.cnblogs.com/yaowen/p/5626783.html,如需转载请自行联系原作者

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

[Android] Android开发优化之——对界面UI的优化(2)

在Android应用开发过程中,屏幕上控件的布局代码和程序的逻辑代码通常是分开的。界面的布局代码是放在一个独立的xml文件中的,这个文件里面是树型组织的,控制着页面的布局。通常,在这个页面中会用到很多控件,控件会用到很多的资源。Android系统本身有很多的资源,包括各种各样的字符串、图片、动画、样式和布局等等,这些都可以在应用程序中直接使用。这样做的好处很多,既可以减少内存的使用,又可以减少部分工作量,也可以缩减程序安装包的大小。 下面从几个方面来介绍如何利用系统资源。 1)利用系统定义的id 比如我们有一个定义ListView的xml文件,一般的,我们会写类似下面的代码片段。 <ListView android:id="@+id/mylist" android:layout_width="fill_parent" android:layout_height="fill_parent"/> 这里我们定义了一个ListView,定义它的id是"@+id/mylist"。实际上,如果没有特别的需求,就可以利用系统定义的id,类似下面的样子。 <ListView android:id="@android:id/list" android:layout_width="fill_parent" android:layout_height="fill_parent"/> 在xml文件中引用系统的id,只需要加上“@android:”前缀即可。如果是在Java代码中使用系统资源,和使用自己的资源基本上是一样的。不同的是,需要使用android.R类来使用系统的资源,而不是使用应用程序指定的R类。这里如果要获取ListView可以使用android.R.id.list来获取。 2)利用系统的图片资源 假设我们在应用程序中定义了一个menu,xml文件如下。 <?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/menu_attachment" android:title="附件" android:icon="@android:drawable/ic_menu_attachment" /> </menu> 其中代码片段android:icon="@android:drawable/ic_menu_attachment"本来是想引用系统中已有的Menu里的“附件”的图标。但是在Build工程以后,发现出现了错误。提示信息如下: error: Error: Resource is not public. (at 'icon' with value '@android:drawable/ic_menu_attachment'). 从错误的提示信息大概可以看出,由于该资源没有被公开,所以无法在我们的应用中直接引用。既然这样的话,我们就可以在Android SDK中找到相应的图片资源,直接拷贝到我们的工程目录中,然后使用类似android:icon="@drawable/ic_menu_attachment"的代码片段进行引用。 这样做的好处,一个是美工不需要重复的做一份已有的图片了,可以节约不少工时;另一个是能保证我们的应用程序的风格与系统一致。 经验分享: Android中没有公开的资源,在xml中直接引用会报错。除了去找到对应资源并拷贝到我们自己的应用目录下使用以外,我们还可以将引用“@android”改成“@*android”解决。比如上面引用的附件图标,可以修改成下面的代码。 android:icon="@*android:drawable/ic_menu_attachment" 修改后,再次Build工程,就不会报错了。 3)利用系统的字符串资源 假设我们要实现一个Dialog,Dialog上面有“确定”和“取消”按钮。就可以使用下面的代码直接使用Android系统自带的字符串。 <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content"> <Button android:id="@+id/yes" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1.0" android:text="@android:string/yes"/> <Button android:id="@+id/no" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1.0" android:text="@android:string/no"/> </LinearLayout> 如果使用系统的字符串,默认就已经支持多语言环境了。如上述代码,直接使用了@android:string/yes和@android:string/no,在简体中文环境下会显示“确定”和“取消”,在英文环境下会显示“OK”和“Cancel”。 4)利用系统的Style 假设布局文件中有一个TextView,用来显示窗口的标题,使用中等大小字体。可以使用下面的代码片段来定义TextView的Style。 <TextView android:id="@+id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" /> 其中android:textAppearance="?android:attr/textAppearanceMedium"就是使用系统的style。需要注意的是,使用系统的style,需要在想要使用的资源前面加“?android:”作为前缀,而不是“@android:”。 5)利用系统的颜色定义 除了上述的各种系统资源以外,还可以使用系统定义好的颜色。在项目中最常用的,就是透明色的使用。代码片段如下。 android:background ="@android:color/transparent" 经验分享: Android系统本身有很多资源在应用中都可以直接使用,具体的,可以进入android-sdk的相应文件夹中去查看。例如:可以进入$android-sdk$\platforms\android-8\data\res,里面的系统资源就一览无余了。 开发者需要花一些时间去熟悉这些资源,特别是图片资源和各种Style资源,这样在开发过程中,能够想到有相关资源并且直接拿来使用。 本文转自农夫山泉别墅博客园博客,原文链接:http://www.cnblogs.com/yaowen/p/5626805.html,如需转载请自行联系原作者

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

Android UI开发第十二篇——动画效果Animation(一)

Android框架本身就使用了大量的动画效果,比如Activity切换的动画效果,Dialog弹出和关闭时的渐变动画效果以及Toast显示信息时的淡入淡出效果等等。Android系统框架为我们提供了一些动画类及其工具类,所以在Andorid应用中使用动画效果非常简单。Android中可以在xml中定义Animation,也可以在java code中定义。 Android中动画的实现分两种方式,一种方式是补间动画 Tween Animation,就是说你定义一个开始和结束,中间的部分由android自身实现。另一种叫逐帧动画 Frame Animation,就是说一帧一帧的连起来播放就变成了动画。 一、Tween Animation xml中实现: alpha 渐变透明度动画效果 scale 渐变尺寸伸缩动画效果 translate 画面转换位置移动动画效果 rotate 画面转移旋转动画效果 JavaCode中 AlphaAnimation 渐变透明度动画效果 ScaleAnimation 渐变尺寸伸缩动画效果 TranslateAnimation 画面转换位置移动动画效果 RotateAnimation 画面转移旋转动画效果 使用XML文件定义Tween Animation时XML文件的根节点可以是<alpha>、<scale> <translate>、<rotate>或者是把它们都放入<set>节点中。如下: <?xml version="1.0" encoding="utf-8"?> < set xmlns:android="http://schemas.android.com/apk/res/android"> <alpha/> <scale/> <translate/> <rotate/> < /set> Java Code实现如下: AlphaAnimation: AnimationSet animationSet =newAnimationSet(true);//创建一个AnimationSet对象 AlphaAnimation alphaAnimation =newAlphaAnimation(1, 0);//创建一个AlphaAnimation对象 alphaAnimation.setDuration(1000);//设置动画执行的时间(单位:毫秒) animationSet.addAnimation(alphaAnimation);//将AlphaAnimation对象添加到AnimationSet当中 view.startAnimation(animationSet);//使用view的startAnimation方法开始执行动画 RotateAnimation : AnimationSet animationSet = newAnimationSet( true); /** * 前两个参数定义旋转的起始和结束的度数,后两个参数定义圆心的位置 */ RotateAnimation rotateAnimation =newRotateAnimation(0, 360, Animation.RELATIVE_TO_PARENT, 1f, Animation.RELATIVE_TO_PARENT, 0f); rotateAnimation.setDuration(5000); animationSet.addAnimation(rotateAnimation); imageView.startAnimation(animationSet); TranslateAnimation: AnimationSet animationSet =newAnimationSet(true); /** * x和y轴的起始和结束位置 */ TranslateAnimation translateAnimation =newTranslateAnimation ( Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF,0.5f, Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 1.0f ); translateAnimation.setDuration(1000); animationSet.addAnimation(translateAnimation); view.startAnimation(animationSet); ScaleAnimation: AnimationSet animationSet =newAnimationSet(true); /** * 围绕一个点伸缩 */ ScaleAnimation scaleAnimation =newScaleAnimation(1, 0.1f, 1, 0.1f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); animationSet.addAnimation(scaleAnimation); animationSet.setStartOffset(1000); animationSet.setFillAfter(true); animationSet.setFillBefore(false); animationSet.setDuration(2000); view.startAnimation(animationSet); 代码下载地址: http://www.devdiv.com/forum.php?mod=viewthread&tid=88504&pid=546599&page=1&extra=#pid546599 本文转自xyz_lmn51CTO博客,原文链接:http://blog.51cto.com/xyzlmn/817314,如需转载请自行联系原作者

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

Android UI开发第八篇——ViewFlipper 左右滑动效果

怎么实现Android主页面的左右拖动效果。其实实现起来很简单,就是使用ViewFlipper来将您要来回拖动的View装在一起,然后与GestureDetector手势识别类来联动,确定要显示哪个View,加上一点点动画效果即可。 java code: public class TestFlip extends Activity implements OnGestureListener { private ViewFlipper flipper; private GestureDetector detector; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); detector = new GestureDetector(this); flipper = (ViewFlipper) this.findViewById(R.id.ViewFlipper01); flipper.addView(addView(R.layout.layout1)); flipper.addView(addView(R.layout.layout2)); flipper.addView(addView(R.layout.layout3)); flipper.addView(addView(R.layout.layout4)); } private View addView(int layout) { LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(layout, null); return view; } @Override public boolean onTouchEvent(MotionEvent event) { return this.detector.onTouchEvent(event); } @Override public boolean onDown(MotionEvent e) { // TODO Auto-generated method stub return false; } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { if (e1.getX() - e2.getX() > 120) { this.flipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.push_left_in)); this.flipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.push_left_out)); this.flipper.showNext(); return true; } else if (e1.getX() - e2.getX() < -120) { this.flipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.push_right_in)); this.flipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.push_right_out)); this.flipper.showPrevious(); return true; } return false; } @Override public void onLongPress(MotionEvent e) { // TODO Auto-generated method stub } @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { // TODO Auto-generated method stub return false; } @Override public void onShowPress(MotionEvent e) { // TODO Auto-generated method stub } @Override public boolean onSingleTapUp(MotionEvent e) { // TODO Auto-generated method stub return false; } } xml code: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <ViewFlipper android:id="@+id/ViewFlipper01" android:layout_width="fill_parent" android:layout_height="fill_parent"> </ViewFlipper> </LinearLayout> http://www.devdiv.com/home.php?mod=space&uid=14682&do=blog&id=3869 本文转自xyz_lmn51CTO博客,原文链接:http://blog.51cto.com/xyzlmn/817361 ,如需转载请自行联系原作者

资源下载

更多资源
优质分享App

优质分享App

近一个月的开发和优化,本站点的第一个app全新上线。该app采用极致压缩,本体才4.36MB。系统里面做了大量数据访问、缓存优化。方便用户在手机上查看文章。后续会推出HarmonyOS的适配版本。

Mario

Mario

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

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Spring

Spring

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

用户登录
用户注册