首页 文章 精选 留言 我的

精选列表

搜索[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 ,如需转载请自行联系原作者

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

Android UI开发第七篇之Android Gallery

新建项目 ② 定义layout外部resource的xml文件,用来改变layout的背景 <?xml version="1.0" encoding="utf-8"?> <resources> <declare-styleable name="Gallery"> <attr name="android:galleryItemBackground" /> </declare-styleable> <!-- 定义layout 外部resource 的xml 文件,用来改变layout 的背景图。 --> </resources> 复制代码 ③ 修改main.xml布局,添加一个Gallery和一个ImageView <?xml version="1.0" encoding="utf-8"?> <AbsoluteLayout android:id="@+id/widget_absolutelayout" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" > <Gallery android:layout_width="fill_parent" android:layout_height="143px" android:layout_x="0px" android:layout_y="51px" android:id="@+id/Gallery_preView"> </Gallery> <ImageView android:layout_width="239px" android:layout_height="218px" android:layout_x="38px" android:layout_y="184px" android:id="@+id/ImageView_photo"> </ImageView> </AbsoluteLayout> 复制代码 ④ 新建一个myImageAdapter类--Gallery的适配器,它继承于BaseAdapter类. package zyf.Ex_Ctrl_10ME; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; public class myImageAdapter extends BaseAdapter { @Override public int getCount() { // TODO Auto-generated method stub return 0; } @Override public Object getItem(int position) { // TODO Auto-generated method stub return null; } @Override public long getItemId(int position) { // TODO Auto-generated method stub return 0; } @Override public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub return null; } } 复制代码 ⑤ 修改mainActivity.java,添加Gallery相关操作 package zyf.Ex_Ctrl_10ME; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.Gallery; import android.widget.ImageView; import android.widget.Toast; public class Ex_Ctrl_10ME extends Activity { /** Called when the activity is first created. */ /*定义要使用的对象*/ privateGallerygallery; private ImageView imageview; private myImageAdapter imageadapter; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); imageadapter=new myImageAdapter(this); /* 通过findViewById 取得 资源对象*/ gallery=(Gallery)findViewById(R.id.Gallery_preView); imageview=(ImageView)findViewById(R.id.ImageView_photo); /*给Gallery设置适配器 把Ex_Ctrl_10ME类传入参数*/ gallery.setAdapter(imageadapter); /*设置Gallery的点击事件监听器*/ gallery.setOnItemClickListener(newGallery.OnItemClickListener(){ @Override public void onItemClick(AdapterView<?> parent, View v, int position, long id) { // TODO Auto-generated method stub /*显示该图片是几号*/ Toast.makeText(Ex_Ctrl_10ME.this, "这是图片:"+position+"号", Toast.LENGTH_SHORT).show(); /*设置大图片*/ imageview.setBackgroundResource(imageadapter.myImageIds[position]); } }); } } 复制代码 ⑥ 修改myImageAdapter.java文件,实现相簿浏览效果 package zyf.Ex_Ctrl_10ME; import android.content.Context; import android.content.res.TypedArray; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.Gallery; import android.widget.ImageView; public class myImageAdapter extends BaseAdapter{//自定义的类变量 /*变量声明*/ int mGalleryItemBackground; private Context context;//上下文 /* 构建一Integer array 并取得预加载Drawable 的图片id */ public Integer[] myImageIds = { R.drawable.photo1, R.drawable.photo2, R.drawable.photo3, R.drawable.photo4, R.drawable.photo5, R.drawable.photo6, }; /*自定义的构造方法*/ public myImageAdapter(Context context) { // TODO Auto-generated constructor stub this.context=context; /* * 使用在res/values/attrs.xml 中的<declare-styleable>定义 的Gallery属性. */ TypedArray typed_array=context.obtainStyledAttributes(R.styleable.Gallery); /* 取得Gallery属性的Index id */ mGalleryItemBackground=typed_array.getResourceId(R.styleable.Gallery_android_galleryItemBackground, 0); /* 让对象的styleable 属性能够反复使用 */ typed_array.recycle(); } /* 重写的方法getCount,返回图片数目 */ @Override public int getCount() { // TODO Auto-generated method stub return myImageIds.length; } /* 重写的方法getItemId,返回图像的数组id */ @Override public Object getItem(int position) { // TODO Auto-generated method stub return position; } @Override public long getItemId(int position) { // TODO Auto-generated method stub return position; } /* 重写的方法getView,返回一View 对象 */ @Override public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub /* 产生ImageView 对象 */ ImageView imageview = new ImageView(context); /* 设置图片给imageView 对象 */ imageview.setImageResource(myImageIds[position]); /* 重新设置图片的宽高 */ imageview.setScaleType(ImageView.ScaleType.FIT_XY); /* 重新设置Layout 的宽高 */ imageview.setLayoutParams(newGallery.LayoutParams(128, 128)); /* 设置Gallery背景图 */ imageview.setBackgroundResource(mGalleryItemBackground); /* 返回imageView 对象 */ return imageview; } } 复制代码 http://www.devdiv.com/home.php?mod=space&uid=14682&do=blog&id=3860 本文转自xyz_lmn51CTO博客,原文链接:http://blog.51cto.com/xyzlmn/817368,如需转载请自行联系原作者

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

Android优化——UI优化(二) 使用include标签复用布局

使用include标签复用布局 - 1.include标签的作用 假如说我下图的这个布局在很多界面都用到了,我该怎么办?每个页面都写一遍的话,代码太冗余,并且维护难度加大。 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" android:orientation="vertical"> <include layout="@layout/activity_clude_item"/> <TextView android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:text="这是中间的东西"/> </LinearLayout> 上边的这个布局我就用的include标签,代码显然更加的整洁,并且增加的布局的复用性,降低了app的使用内存 - 2.include标签的用法 <include layout="@layout/activity_clude_item"/> 1 其中我们使用layout="@layout/activity_clude_item"设置复用的布局文件 本文转自 一点点征服 博客园博客,原文链接: http://www.cnblogs.com/ldq2016/p/5226576.html ,如需转载请自行联系原作者

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

Android UI开发第五篇——自定义列表

自定义列表,设置列表背景、列表的列背景、列表的间隔线。 借鉴了一些前辈的代码。 MainActivity.class public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //绑定Layout里面的ListView ListView list = (ListView) findViewById(R.id.ListView01); //生成动态数组,加入数据 ArrayList<HashMap<String, Object>> listItem = new ArrayList<HashMap<String, Object>>(); for(int i=0;i<5;i++) { if(i==0){ HashMap<String, Object> map = new HashMap<String, Object>(); map.put("ItemImage", R.drawable.checked);//图像资源的ID map.put("ItemTitle", "个人信息"); map.put("LastImage", R.drawable.lastimage); listItem.add(map); }else if(i==1){ HashMap<String, Object> map = new HashMap<String, Object>(); map.put("ItemImage", R.drawable.c);//图像资源的ID map.put("ItemTitle", "修改密码"); map.put("LastImage", R.drawable.lastimage); listItem.add(map); }else if(i==2){ HashMap<String, Object> map = new HashMap<String, Object>(); map.put("ItemImage", R.drawable.d);//图像资源的ID map.put("ItemTitle", "网络设置"); map.put("LastImage", R.drawable.lastimage); listItem.add(map); }else if(i==3){ HashMap<String, Object> map = new HashMap<String, Object>(); map.put("ItemImage", R.drawable.d);//图像资源的ID map.put("ItemTitle", "打印设置"); map.put("LastImage", R.drawable.lastimage); listItem.add(map); }else{ HashMap<String, Object> map = new HashMap<String, Object>(); map.put("ItemImage", R.drawable.e);//图像资源的ID map.put("ItemTitle", "返回"); map.put("LastImage", R.drawable.lastimage); listItem.add(map); } } //生成适配器的Item和动态数组对应的元素 SimpleAdapter listItemAdapter = new SimpleAdapter(this,listItem,// 数据源 R.layout.list_items,//ListItem的XML实现 //动态数组与ImageItem对应的子项 new String[] {"ItemImage","ItemTitle", "LastImage"}, //ImageItem的XML文件里面的一个ImageView,两个TextView ID new int[] {R.id.ItemImage,R.id.ItemTitle,R.id.last} ); //添加并且显示 list.setAdapter(listItemAdapter); //添加点击 list.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { setTitle("点击第"+arg2+"个项目"); if(arg2 == 4){ MainActivity.this.finish(); } } }); //添加长按点击 list.setOnCreateContextMenuListener(new OnCreateContextMenuListener() { @Override public void onCreateContextMenu(ContextMenu menu, View v,ContextMenuInfo menuInfo) { menu.setHeaderTitle("长按菜单-ContextMenu"); menu.add(0, 0, 0, "弹出长按菜单0"); menu.add(0, 1, 0, "弹出长按菜单1"); } }); } //长按菜单响应函数 @Override public boolean onContextItemSelected(MenuItem item) { setTitle("点击了长按菜单里面的第"+item.getItemId()+"个项目"); return super.onContextItemSelected(item); } } main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout android:id="@+id/LinearLayout01" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ffffff" xmlns:android="http://schemas.android.com/apk/res/android"> <ListView android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/ListView01" android:divider="@drawable/divider_color" android:dividerHeight="3dip" android:cacheColorHint="#00000000" /> </LinearLayout> list_item.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout android:id="@+id/RelativeLayout01" android:layout_width="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="wrap_content" android:paddingBottom="4dip" android:paddingLeft="12dip" android:paddingRight="12dip" android:background="@drawable/list_bg"> <ImageView android:paddingTop="12dip" android:layout_alignParentLeft="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/ItemImage" /> <TextView android:text="TextView01" android:layout_height="wrap_content" android:layout_marginTop="30px" android:textSize="20dip" android:paddingLeft="12dip" android:textColor="#000000" android:layout_width="fill_parent" android:id="@+id/ItemTitle" android:layout_toRightOf="@+id/ItemImage" /> <ImageView android:paddingTop="12dip" android:layout_marginTop="20px" android:layout_alignParentRight="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/last" /> </RelativeLayout> http://www.devdiv.com/home.php?mod=space&uid=14682&do=blog&id=2888 http://www.devdiv.com/home.php?mod=space&uid=14682&do=blog&id=2888 http://www.devdiv.com/home.php?mod=space&uid=14682&do=blog&id=2888 http://www.devdiv.com/forum.php?mod=viewthread&tid=97913&page=1#pid591587 http://blog.csdn.net/zeng622peng/archive/2010/08/11/5804965.aspx http://www.devdiv.com/home.php?mod=space&uid=14682&do=blog&id=2888 本文转自xyz_lmn51CTO博客,原文链接:http://blog.51cto.com/xyzlmn/817375 ,如需转载请自行联系原作者

资源下载

更多资源
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应用均可从中受益。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册