现在的位置: 首页 > 综合 > 正文

Android开发_android界面效果全汇总

2013年08月15日 ⁄ 综合 ⁄ 共 26261字 ⁄ 字号 评论关闭

(一)Activity页面切换的效果

 

先介绍下左右滑动切换Activity,对于复杂的手势原理一样,具体后述。

主要原理为监控触屏事件和手势事件,在触屏事件处理函数中调用手势事件处理函数,表示用户触屏后是否有手势操作,有则进行手势事件处理,大致分为四步

 

1、需要继承OnGestureListener和OnDoubleTapListener,如下:

Java代码
复制代码
 收藏代码
  1. public class ViewSnsActivity extends Activity implements OnTouchListener, OnGestureListener  

 

这两个类分别是触屏监听器和手势监控器,具体可查看OnTouchListenerOnGestureListener

 

2、在添加mGestureDetector的定义,并在ViewSnsActivity的onCreate函数中加入其页面布局的setOnTouchListener事件

Java代码
复制代码
 收藏代码
  1. GestureDetector mGestureDetector;  

  

Java代码
复制代码
 收藏代码
  1. public void onCreate(Bundle savedInstanceState) {  
  2.         super.onCreate(savedInstanceState);  
  3.         setContentView(R.layout.view_sns_activity);  
  4.           
  5.         mGestureDetector = new GestureDetector((OnGestureListener) this);    
  6.         LinearLayout viewSnsLayout = (LinearLayout)findViewById(R.id.viewSnsLayout);    
  7.         viewSnsLayout.setOnTouchListener(this);    
  8.         viewSnsLayout.setLongClickable(true);    
  9.     }  

 

mGestureDetector为手势监听对象,下面的OnFling就是为其实现,用来处理手势的

viewSnsLayout.setOnTouchListener(this);表示viewSnsLayout这个layout的触屏事件由下面的OnTouch处理

 

3、重载onFling函数

Java代码
复制代码
 收藏代码
  1. private int verticalMinDistance = 20;  
  2. private int minVelocity         = 0;  
  3.   
  4. public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {  
  5.   
  6.     if (e1.getX() - e2.getX() > verticalMinDistance && Math.abs(velocityX) > minVelocity) {  
  7.   
  8.         // 切换Activity  
  9.         // Intent intent = new Intent(ViewSnsActivity.this, UpdateStatusActivity.class);  
  10.         // startActivity(intent);  
  11.         Toast.makeText(this"向左手势", Toast.LENGTH_SHORT).show();  
  12.     } else if (e2.getX() - e1.getX() > verticalMinDistance && Math.abs(velocityX) > minVelocity) {  
  13.   
  14.         // 切换Activity  
  15.         // Intent intent = new Intent(ViewSnsActivity.this, UpdateStatusActivity.class);  
  16.         // startActivity(intent);  
  17.         Toast.makeText(this"向右手势", Toast.LENGTH_SHORT).show();  
  18.     }  
  19.   
  20.     return false;  
  21. }  

 

OnFling的四个参数意思分别为

Xml代码
复制代码
 收藏代码
  1. e1  The first down motion event that started the fling.手势起点的移动事件  
  2. e2  The move motion event that triggered the current onFling.当前手势点的移动事件  
  3. velocityX   The velocity of this fling measured in pixels per second along the x axis.每秒x轴方向移动的像素  
  4. velocityY   The velocity of this fling measured in pixels per second along the y axis.每秒y轴方向移动的像素  

 

说的更简单点就是,鼠标手势相当于一个向量(当然有可能手势是曲线),e1为向量的起点,e2为向量的终点,velocityX为向量水平方向的速度,velocityY为向量垂直方向的速度

Java代码
复制代码
 收藏代码
  1. if (e1.getX() - e2.getX() > verticalMinDistance && Math.abs(velocityX) > minVelocity)  

 

 则上面的语句能知道啥意思了吧,就是说向量的水平长度必须大于verticalMinDistance,并且水平方向速度大于minVelocity

 

从而我们可以如此判断手势是否满足一定的条件从而进行相应响应,也可以根据这个写出更复杂的手势判断。

 

4、重载onTouch函数

在2中我们定义了viewSnsLayout的touch事件处理,下面我们来实现,直接调用手势的处理函数

Java代码
复制代码
 收藏代码
  1. public boolean onTouch(View v, MotionEvent event) {  
  2.     return mGestureDetector.onTouchEvent(event);  
  3. }  

 

查看GestureDetector类的onTouchEvent的源码就能知道,进入该函数后会进入case MotionEvent.ACTION_UP这个路径,从而调用onFling函数

 

如果需要设置activity切换效果,在startActivity(intent);之后添加

overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right);即可,可修改相应参数,可参考http://www.iteye.com/topic/1116472

 

其他:

关于activity添加ScrollView后或是外部为RelativeLayout时onFling不起作用,无法滑动问题见http://trinea.iteye.com/blog/1213815

 

 

Android 2.0之后有了overridePendingTransition(),其中里面两个参数,一个是前一个activity的退出两一个activity的进入,

Java代码 

1. @Override     public void onCreate(BundlesavedInstanceState) {    

2. super.onCreate(savedInstanceState);      3.    

4.   setContentView(R.layout.SplashScreen);     5.      

6.              new Handler().postDelayed(new Runnable() {    

7.              @Override    

8.              public void run() {    

9.              Intent mainIntent = newIntent(SplashScreen.this,        AndroidNews.class);    

10.           SplashScreen.this.startActivity(mainIntent);    

11.           SplashScreen.this.finish();     12.    

13.                                                           overridePendingTransition(R.anim.mainfadein,    

14.                                                           R.anim.splashfadeout);    

15.                                                           }     

16.}, 3000);    

}   

 

上面的代码只是闪屏的一部分。

Java代码  

1. getWindow ().setWindowAnimations ( int );    

 这可没有上个好但是也可以 。

实现淡入淡出的效果 

Java代码  

1. overridePendingTransition(Android.R.anim.fade_in,android.R.anim

.fade_out);    

 由左向右滑入的效果 

Java代码  

1. overridePendingTransition(Android.R.anim.slide_in_left,android.

R.anim.slide_out_right);       实现zoomin和zoomout,即类似iphone的进入和退出时的效果 

Java代码  

1. overridePendingTransition(R.anim.zoomin,R.anim.zoomout); 

     新建zoomin.xml文件 

Xml代码  

1.       <?xml version="1.0"encoding="utf-8"?>  

2.       <set 

3.       xmlns:Android="http://schemas.android.com/apk/res/android"  

4.       Android:interpolator="@android:anim/decelerate_interpolator">

<scale Android:fromXScale="2.0"android:toXScale="1.0"  

5.       Android:fromYScale="2.0"android:toYScale="1.0"  

6.       Android:pivotX="50%p"android:pivotY="50%p"  

7.       Android:duration="@android:integer/config_mediumAnimTime"/>
</set>     新建zoomout.xml文件 

Xml代码  

1.        <?xml version="1.0"encoding="utf-8"?>  

2.        <set 

3.        xmlns:Android="http://schemas.android.com/apk/res/android"  

4.        Android:interpolator="@android:anim/decelerate_interpolator"

5.        Android:zAdjustment="top">  

6.        <scale Android:fromXScale="1.0"android:toXScale=".5"  

7.        Android:fromYScale="1.0"android:toYScale=".5"  

8.        Android:pivotX="50%p"android:pivotY="50%p"  

9.        Android:duration="@android:integer/config_mediumAnimTime"/>

  

10.<alpha Android:fromAlpha="1.0"android:toAlpha="0"  

11.Android:duration="@android:integer/config_mediumAnimTime"/>  

12.</set>   

(二)android 菜单动画

先请注意,这里的菜单并不是按机器上的MENU出现在那种菜单,而是基于

Android SDK 提供的android.view.animation.TranslateAnimationextends

android.view.animation.Animation)类实例后附加到一个Layout上使之产生的有动画出现和隐藏效果的菜单。

        原理:Layout(菜单)从屏幕内(挨着屏幕边沿,其实并非一定,视需要的初态和末态而定)动态的移动到屏幕外(在外面可以挨着边沿,也可以离远点,这个无所谓了),这样就可以达到动态菜单的效果了。但

是由于Animation的一些奇怪特性(setFill**() 函数的作用效果,这个在我使用的某几个Animation当中出现了没有想明白的效果),就暂不理会这个东西了,所以使得我们还需要用上XML属性android:visibility。当Layout(菜单)显示的时候,设置android:visibility="visible",当Layout(菜单)隐藏的时候,设置android:visibility="gone",这里android:visibility可以有3个值,"visible"为可见"invisible"为不可见但占空间"gone"为不可见且不占空间(所谓的占不占空间,这个可以自己写个XML来试试就明白了)。

        Class TranslateAnimation的使用:Animation有两种定义方法,一种是用Java code,一种是用XML,这里只介绍用code来定义(因为用 XML来定义的那种我没用过。。嘿嘿。。)。多的不说,看代码。

这里是TranslateAnimationMenu.java(我在里面还另加入了ScaleAnimation

产生的动画,各位朋友可以照着SDK以及程序效果来理解)

packagecom.TranslateAnimation.Menu;

importandroid.app.Activity; import android.os.Bundle; import android.view.View;import android.view.View.OnClickListener; importandroid.view.animation.Animation; importandroid.view.animation.TranslateAnimation; import android.widget.Button;
importandroid.widget.LinearLayout;

public classTranslateAnimationMenu extends Activity {    /** Called when the activity is first created. */

    //TranslateAnimation showAction,hideAction;

    Animation showAction, hideAction;

    LinearLayout menu;     Button button;

    boolean menuShowed;

    

    @Override

    public void onCreate(BundlesavedInstanceState) 

{     super.onCreate(savedInstanceState);     setContentView(R.layout.main);     menu = (LinearLayout) findViewById(R.id.menu);

    button = (Button)findViewById(R.id.button);     //这里是TranslateAnimation动画    showAction = newTranslateAnimation(

Animation.RELATIVE_TO_SELF,0.0f,Animation.RELATIVE_TO_SELF,

0.0f,Animation.RELATIVE_TO_SELF, -1.0f, Animation.RELATIVE_TO_SELF, 0.0f);

// 这里是ScaleAnimation动画 

//showAction = newScaleAnimation(

//    1.0f, 1.0f, 0.0f, 1.0f,Animation.RELATIVE_TO_SELF, 0.0f,

//       Animation.RELATIVE_TO_SELF, 0.0f);showAction.setDuration(500);

 

// 这里是TranslateAnimation动画        

hideAction= new TranslateAnimation(  Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f,

Animation.RELATIVE_TO_SELF,0.0f, Animation.RELATIVE_TO_SELF, -1.0f); //这里是ScaleAnimation动画

//hideAction = newScaleAnimation(

//        1.0f, 1.0f, 1.0f, 0.0f,    

Animation.RELATIVE_TO_SELF,0.0f, Animation.RELATIVE_TO_SELF,

0.0f);

 hideAction.setDuration(500); menuShowed =false; menu.setVisibility(View.GONE);

button.setOnClickListener(newOnClickListener() {

   @Override

   public void onClick(View v) {    // TODO Auto-generated method stub       if (menuShowed) {        menuShowed = false;        menu.startAnimation(hideAction);

       menu.setVisibility(View.GONE);

    }

    else {      menuShowed = true;      menu.startAnimation(showAction);

      menu.setVisibility(View.VISIBLE);

    }

   }

            

  });

 }

}

这里是main.xml

<?xmlversion="1.0" encoding="utf-8"?>

<RelativeLayout

xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent"> <TextViewandroid:layout_width="fill_parent"   android:layout_height="wrap_content"
android:text="@string/hello"/> <LinearLayout android:id="@+id/menu"

   android:layout_height="100px"android:layout_width="fill_parent"   android:layout_alignParentTop="true"android:background="#ffffff">

   <TextViewandroid:layout_width="fill_parent"

    android:layout_height="fill_parent"android:text="I am a menu"    android:gravity="center" />

</LinearLayout>

<Buttonandroid:id="@+id/button"android:layout_width="fill_parent"   android:layout_height="wrap_content"android:layout_alignParentBottom="true"    android:text="Click to show/hidemenu" />

</RelativeLayout>Android基于TranslateAnimation的动画动态菜单

android布局属性

文章分类:移动开发 

第一类:属性值为true或false 

    android:layout_centerHrizontal  水平居中      android:layout_centerVertical   垂直居中      android:layout_centerInparent    相对于父元素完全居中      android:layout_alignParentBottom 贴紧父元素的下边缘     android:layout_alignParentLeft   贴紧父元素的左边缘     android:layout_alignParentRight 
贴紧父元素的右边缘      android:layout_alignParentTop    贴紧父元素的上边缘 

   android:layout_alignWithParentIfMissing 如果对应的兄弟元素找

不到的话就以父元素做参照物 

 

    第二类:属性值必须为id的引用名“@id/id-name”     android:layout_below      在某元素的下方     android:layout_above      在某元素的的上方     android:layout_toLeftOf   在某元素的左边 

    android:layout_toRightOf  在某元素的右边 

 

    android:layout_alignTop 本元素的上边缘和某元素的的上边缘对齐      android:layout_alignLeft本元素的左边缘和某元素的的左边缘对齐     android:layout_alignBottom本元素的下边缘和某元素的的下边缘对齐 

    android:layout_alignRight本元素的右边缘和某元素的的右边缘对齐 

 

    第三类:属性值为具体的像素值,如30dip,40px      android:layout_marginBottom      离某元素底边缘的距离      android:layout_marginLeft       离某元素左边缘的距离      android:layout_marginRight       离某元素右边缘的距离      android:layout_marginTop        离某元素上边缘的距离  EditText的android:hint 

设置EditText为空时输入框内的提示信息。 

android:gravity  

android:gravity属性是对该view 内容的限定.比如一个button 上面的

text.  你可以设置该text 在view的靠左,靠右等位置.以button为例,

android:gravity="right"则button上面的文字靠右  android:layout_gravity 

android:layout_gravity是用来设置该view相对与起父view 的位置.比如一个button 在linearlayout里,你想把该button放在靠左、靠右等位置就可以通过该属性设置.以button为例,android:layout_gravity="right"则button 靠右 

 

android:layout_alignParentRight 

使当前控件的右端和父控件的右端对齐。这里属性值只能为true或false,默认false。 

 

android:scaleType:  android:scaleType是控制图片如何resized/moved来匹对ImageView的size。

ImageView.ScaleType /android:scaleType值的意义区别: 

 

CENTER /center  按图片的原来size居中显示,当图片长/宽超过View的长/

宽,则截取图片的居中部分显示 

 

CENTER_CROP / centerCrop  按比例扩大图片的size居中显示,使得图片长(宽)

等于或大于View的长(宽) 

 

CENTER_INSIDE /centerInside  将图片的内容完整居中显示,通过按比例缩小或原来的size使得图片长/宽等于或小于View的长/宽 

 

FIT_CENTER / fitCenter  把图片按比例扩大/缩小到View的宽度,居中显示 

 

FIT_END / fitEnd   把图片按比例扩大/缩小到View的宽度,显示在View

的下部分位置 

 

FIT_START / fitStart  把图片按比例扩大/缩小到View的宽度,显示在View

的上部分位置 

 

FIT_XY / fitXY  把图片•不按比例扩大/缩小到View的大小显示 

 

MATRIX / matrix 用矩阵来绘制,动态缩小放大图片来显示。 

 

** 要注意一点,Drawable文件夹里面的图片命名是不能大写的。 

2010-10-28

android翻页

:   

之前看到不少翻页,不过人家没有分享出代码来,我也一直没有搞出来. 

想了好久,实现原理并不是那么的难,怎么实现就比较难了. 

 

当然像3D现实模拟分页的难度是比较大的. 

 

平面的分页,简单点说就是用三张片,模拟分页时可见区, 这里我弄了一个View,里面有翻页的效果. 

 

OnDraw中; 

最底一张是将要显示的,先画出来, 

接着画原来那张,放中间,叠为这张片要翻页的过程中慢慢消失,一点一点被拉出去, 

最后一张就是最上面的,为什么要用这张片呢?当页面被翻起后,一个角消失了, 就比如第二张不显示的部分,那这部分,就是第三张了,再覆盖第二张上面,形成一种看似翻书的.效果. 

 

然后第二张(假设从左边开始被翻起,左边先消失),左边缘再画出一条线,当然这条线要粗点,然后设置颜色渐变,还要透明的,就有一种阴影的效果. 

 

我开始一直想,像这样的,不难实现啊,当然只限于矩形的,叠为当时没有想到如何处理第二张消失部分为一个三角形. 

 

可以通过Rect来设置一个Bitmap,的宽度. 

Rect rect = new Rect(mWidth, 0,width, height); 

canvas.drawBitmap(image2, null,rect, paint2); 

mWidth就是左边消失部分的宽度.通过不断改变这个值,然后再刷新View就可以

看到一种滚动的效果.第二张片左边慢慢消失, width,height为画面目的宽高. 

 

然后可以添加一个第三张片,也用同样的方法设置了它显示的宽,高, 

 

通过上面Rect的处理,看到一般的效果.比较常见的是从一个角开始,然后慢慢

的卷起来,而不是像上面平行的,(上面只能看到平行的效果.) 

 

这里就涉及到了一个角,就是三角形如何产生的问题,这个问题台扰了好久.今天想到办法了.就是用Path去画多边形.一个矩形,减去一个多边形,就剩下一个三角形了. 

 

先讨论上面那种效果的处理方式: 

首先是View:的OnDraw方法. 

Java代码  

1.    width =getWidth();   

2.    height =getHeight();   

3.    //画最底下一张将要显示的图片   

4.    Rect rect = newRect(0,
0
, width, height);   5. canvas.drawBitmap(image1, null, rect, paint1);   

6.    //画上面卷起的那张.实现平行翻页效果.   

7.    rect = newRect(mWidth, 0, width, height);   

8.    canvas.drawBitmap(image2,null, rect, paint2);   

9.    //当然之后再处理卷起边缘阴影,模糊等效果,这里省略了.还有图片

Image1,image2自己准备了   

10.然后就是手势,没有手势,翻页显得很呆板.   

11.这个View实现OnGestureListener,自然有一些方法要覆盖的.   

12.其它方法随便了,有返回值的给它一个True,主要是   

13.public booleanonFling(MotionEvent e1, MotionEvent e2, fl oat velocityX, float velocityY)这个方法,比较有用.   

14.myHandler.removeMessage(0);/../我觉得要先移除上一次翻页的动作,然后会马上从上一次运行中停止,而立即向当前需要的方向变化.   

15.if(e1.getX() - e2.getX() >0){   

16.   turnLeft(5);//向左翻   

17.}else if(e2.getX() -e1.getX() > 0){   

18.   turnRight(5);//向右翻   

19.}   

20.两个方法差不多,也可以合并,传入正负值.   

21.delta = speed;参数就是上面的5,作为变化速度.   

22.myHandler.sendEmptyMessage(0);   

23.普通的View要Handler来更新.之前试过了,以为在View直接Invalidate 可以.   

24.虽然没有提示非UI线程的问题,但是循环了多次只看到OnDraw执行一次而以.   

25.public voidhandleMessage(Message message){   

26.        invalidate();   

27.        mWidth += delta;//变化第二张图片的宽.   

28.        if(delta > 0){//向右滚动   

29.        if(mWidth < width){//当第二张图片的左侧空白超过了画布的宽                时停止   

30.        sendEmptyMessage(0);   

31.        }   

32.}else{//向左滚动   

33.if(mWidth > 0){   

34.   sendEmptyMessage(0);   

35.}    36.}   

37.}    38. 

39.然后在XML里用这个View,最后Activity里SetContentView就OK了

/   

40.<com.me.page.PageView   

41.android:id="@+id/pageView1"  

42.android:layout_gravity="center"

43.android:layout_marginTop="5px" 

44.android:layout_width="fill_parent" 45.android:layout_height="fill_parent"/>    46.  

47.由于使用XML,所以构造方法必须要有,带两个参数的.   

48.public PageView(Contextcontext, AttributeSet attrs){   

49.           super(context, attrs);   

50.           initView();   

51.}    52.InitView:   

53.private void initView(){   

54.           image1 =Bitmap.createBitmap(BitmapFactory.decodeResource (getResources(),R.drawable.aac));   

55.           image2 =Bitmap.createBitmap(BitmapFactory.decodeResource (getResources(),R.drawable.q1));    

56.           image3 =Bitmap.createBitmap(BitmapFactory.decodeResource

(getResources(),R.drawable.q2));   

57.  

58.                myHandler = new MyHandler();   

59.                gestureDetector = new GestureDetector(this);   

60.                mShader = new LinearGradient(10,250,
250, 250,   

61.                new int[]{Color.RED, Color.GREEN, Color.BLUE},   

62.                null, Shader.TileMode.MIRROR);   

63.                paint1 = new Paint();   

64.                paint1.setFlags(Paint.ANTI_ALIAS_FLAG); //去除插刺  

65.                paint2 = new Paint(paint1);   

66.                paint3 = new Paint(paint2);   

67.                paint3.setColor(0x45111111);   

68.                //paint.setShader(mShader);//其间颜色会有变化.   

69.                paint3.setStrokeWidth(12);   

70.                paint4 = new Paint(paint2);   

71.                paint4.setColor(0xff111111);   

72.                paint4.setShader(mShader);//其间颜色会有变化.   

73.                paint4.setStrokeWidth(12);    74. }   

75.  

76.代码就到这里了.关于三角形卷动翻页,代码没有写完整,(第三张图片还没有弄,也没有阴影),先不写了,而且似乎也不止我这样一种写法的,网上看到的翻页还有其它的,比如我见到一个,OnDraw里得到画布的高,然后一行一行描述,并逐行递减宽度,这样造成一个三角形,速度也不那么地慢. 还可接受.   

77.  

78.来些图片.   

79.page-15.png到page-16.png,宽度越来越小了.   

80.page-12.png到page-14.png是三角形的,里面具体操作复杂一些,当前差上面那张遮罩.以后再完善了.

81.android中颜色对应的值

82.文章分类:移动开发 

83.  < ?xml version="1.0"encoding="utf-8" ?> 

 

 < resources> 

 

 < color name="white">#FFFFFF< /color>< !--白色 -->  

 < color name="ivory">#FFFFF0< /color>< !--象牙色 --> 

 

 < color name="lightyellow">#FFFFE0< /color><!--亮黄色 --> 

 

 < color name="yellow">#FFFF00< /color>< !--黄色 --> 

 

 < color name="snow">#FFFAFA< /color>< !--雪白色 --> 

 

 < color name="floralwhite">#FFFAF0< /color><!--花白色 -->  

 < color name="lemonchiffon">#FFFACD< /color><!--柠檬绸色 -->  

 < color name="cornsilk">#FFF8DC< /color>< !--米绸色 --> 

 

 < color name="seashell">#FFF5EE< /color>< !--海贝色 -->  

 < color name="lavenderblush">#FFF0F5< /color><!--淡紫红 -->  

 < color name="papayawhip">#FFEFD5< /color>< !--番木色 -->  

 < color name="blanchedalmond">#FFEBCD< /color><!--白杏色 -->  

 < color name="mistyrose">#FFE4E1< /color>< !--浅玫瑰色-->  

 < color name="bisque">#FFE4C4< /color>< !--桔黄色 --> 

< colorname="moccasin">#FFE4B5< /color>< !--鹿皮色 --> 

< color name="navajowhite">#FFDEAD< /color>< !--纳瓦白 --> 

< color name="peachpuff">#FFDAB9< /color>< !--桃色 --> 

 

 < color name="gold">#FFD700< /color>< !--金色 -->  

 < color name="pink">#FFC0CB< /color>< !--粉红色 --> 

 

 < color name="lightpink">#FFB6C1< /color>< !--亮粉红色--> 

 

 < color name="orange">#FFA500< /color>< !--橙色 --> 

 

 < color name="lightsalmon">#FFA07A< /color><!--亮肉色 -->  

 < color name="darkorange">#FF8C00< /color>< !--暗桔黄色--> 

 

 < color name="coral">#FF7F50< /color>< !--珊瑚色 -->  

 < color name="hotpink">#FF69B4< /color>< !--热粉红色-->  

 < color name="tomato">#FF6347< /color>< !--西红柿色-->  

 < color name="orangered">#FF4500< /color>< !--红橙色 -->  

 < color name="deeppink">#FF1493< /color>< !--深粉红色-->  

 < color name="fuchsia">#FF00FF< /color>< !--紫红色 --> 

 

 < color name="magenta">#FF00FF< /color>< !--红紫色 --> 

 

 < color name="red">#FF0000< /color>< !--红色 -->  

 

 < color name="oldlace">#FDF5E6< /color>< !--老花色 -->  

 < color name="lightgoldenrodyellow">#FAFAD2</color>< !--亮金黄色 --> 

 

 < color name="linen">#FAF0E6< /color>< !--亚麻色 --> 

 

 < color name="antiquewhite">#FAEBD7< /color><!--古董白 --> 

 

 < color name="salmon">#FA8072< /color>< !--鲜肉色 -->  

 < color name="ghostwhite">#F8F8FF< /color>< !--幽灵白 -->    < colorname="mintcream">#F5FFFA< /color>< !--薄荷色 -->  

 < color name="whitesmoke">#F5F5F5< /color>< !--烟白色 --> 

 

 < color name="beige">#F5F5DC< /color>< !--米色 -->  

 < color name="wheat">#F5DEB3< /color>< !--浅黄色 -->  

 < color name="sandybrown">#F4A460< /color>< !--沙褐色 -->  

 < color name="azure">#F0FFFF< /color>< !--天蓝色 -->  

 < color name="honeydew">#F0FFF0< /color>< !--蜜色 -->  

 < color name="aliceblue">#F0F8FF< /color>< !--艾利斯兰--> 

 

 < color name="khaki">#F0E68C< /color>< !--黄褐色 --> 

 

 < color name="lightcoral">#F08080< /color>< !--亮珊瑚色-->  

 < color name="palegoldenrod">#EEE8AA< /color><!--苍麒麟色 -->  

 < color name="violet">#EE82EE< /color>< !--紫罗兰色-->  

 < color name="darksalmon">#E9967A< /color>< !--暗肉色 -->  

 < color name="lavender">#E6E6FA< /color>< !--淡紫色 -->  

 < color name="lightcyan">#E0FFFF< /color>< !--亮青色 --> 

 

 < color name="burlywood">#DEB887< /color>< !--实木色 -->  

 < color name="plum">#DDA0DD< /color>< !--洋李色 -->  

 < color name="gainsboro">#DCDCDC< /color>< !--淡灰色 --> 

 

 < color name="crimson">#DC143C< /color>< !--暗深红色-->  

 < color name="palevioletred">#DB7093< /color><!--苍紫罗兰色

--> 

< color name="goldenrod">#DAA520< /color>< !--金麒麟色-->  < colorname="orchid">#DA70D6< /color>< !--淡紫色 --> 

< colorname="thistle">#D8BFD8< /color>< !--蓟色 --> 

 

 < color name="lightgray">#D3D3D3< /color>< !--亮灰色 --> 

 

 < color name="lightgrey">#D3D3D3< /color>< !--亮灰色 --> 

 

 < color name="tan">#D2B48C< /color>< !--茶色 --> 

 

 < color name="chocolate">#D2691E< /color>< !--巧可力色--> 

 

 < color name="peru">#CD853F< /color>< !--秘鲁色 --> 

 

 < color name="indianred">#CD5C5C< /color>< !--印第安红-->  

 < color name="mediumvioletred">#C71585</color>< !--中紫罗兰色 --> 

 

 < color name="silver">#C0C0C0< /color>< !--银色 -->  

 < color name="darkkhaki">#BDB76B< /color>< !--暗黄褐色  

 < color name="rosybrown">#BC8F8F< /color>< !--褐玫瑰红-->  

 < color name="mediumorchid">#BA55D3< /color><!--中粉紫色 -->  

 < color name="darkgoldenrod">#B8860B< /color><!--暗金黄色 -->  

 < color name="firebrick">#B22222< /color>< !--火砖色 -->  

 < color name="powderblue">#B0E0E6< /color>< !--粉蓝色 -->  

 < color name="lightsteelblue">#B0C4DE< /color><!--亮钢兰色

--> 

 

 < color name="paleturquoise">#AFEEEE< /color><!--苍宝石绿 -->  

 < color name="greenyellow">#ADFF2F< /color><!--黄绿色 -->  

 < color name="lightblue">#ADD8E6< /color>< !--亮蓝色 --> 

< color name="darkgray">#A9A9A9</color>< !--暗灰色 --> 

< color name="darkgrey">#A9A9A9< /color>< !--暗灰色 --> 

< colorname="brown">#A52A2A< /color>< !--褐色 --> 

 

 < color name="sienna">#A0522D< /color>< !--赭色 --> 

 

 < color name="darkorchid">#9932CC< /color>< !--暗紫色 -->  

 < color name="palegreen">#98FB98< /color>< !--苍绿色 -->  

 < color name="darkviolet">#9400D3< /color>< !--暗紫罗兰色-->  

 < color name="mediumpurple">#9370DB< /color><!--中紫色 -->  

 < color name="lightgreen">#90EE90< /color>< !--亮绿色 -->   

 < color name="darkseagreen">#8FBC8F< /color><!--暗海兰色 -->  

 < color name="saddlebrown">#8B4513< /color><!--重褐色 --> 

 

 < color name="darkmagenta">#8B008B< /color><!--暗洋红 -->  

 < color name="darkred">#8B0000< /color>< !--暗红色 -->  

 < color name="blueviolet">#8A2BE2< /color>< !--紫罗兰蓝色  

 < color name="lightskyblue">#87CEFA< /color><!--亮天蓝色 -->  

 < color name="skyblue">#87CEEB< /color>< !--天蓝色 --> 

 

 < color name="gray">#808080< /color>< !--灰色 --> 

 

 < color name="grey">#808080< /color>< !--灰色 -->  

 < color name="olive">#808000< /color>< !--橄榄色 -->  

 < color name="purple">#800080< /color>< !--紫色 --> 

 

 < color name="maroon">#800000< /color>< !--粟色 --> 

 

 < color name="aquamarine">#7FFFD4< /color>< !--碧绿色 --> 

< color name="chartreuse">#7FFF00< /color>< !--黄绿色 -->  < colorname="lawngreen">#7CFC00< /color>< !--草绿色 --> 

< color name="mediumslateblue">#7B68EE< /color><!--中暗蓝色

--> 

 

 < color name="lightslategray">#778899< /color><!--亮蓝灰 --> 

 

 < color name="lightslategrey">#778899< /color><!--亮蓝灰 -->  

 < color name="slategray">#708090< /color>< !--灰石色 --> 

 

 < color name="slategrey">#708090< /color>< !--灰石色 -->  

 < color name="olivedrab">#6B8E23< /color>< !--深绿褐色-->  

 < color name="slateblue">#6A5ACD< /color>< !--石蓝色 -->  

 < color name="dimgray">#696969< /color>< !--暗灰色 --> 

 

 < color name="dimgrey">#696969< /color>< !--暗灰色 -->  

 < color name="mediumaquamarine">#66CDAA</color>< !--中绿色

--> 

 

 < color name="cornflowerblue">#6495ED< /color><!--菊兰色 -->  

 < color name="cadetblue">#5F9EA0< /color>< !--军兰色 -->  

 < color name="darkolivegreen">#556B2F< /color><!--暗橄榄绿 

 

 < color name="indigo">#4B0082< /color>< !--靛青色 -->  

 < color name="mediumturquoise">#48D1CC</color>< !--中绿宝石

--> 

 

 < color name="darkslateblue">#483D8B< /color><!--暗灰蓝色 -->  

 < color name="steelblue">#4682B4< /color>< !--钢兰色 --> 

 

 < color name="royalblue">#4169E1< /color>< !--皇家蓝 --> 

 

 < color name="turquoise">#40E0D0< /color>< !--青绿色 -->  

  < colorname="mediumseagreen">#3CB371< /color>< !--中海蓝 -->    < colorname="limegreen">#32CD32< /color>< !--橙绿色 -->  

 < color name="darkslategray">#2F4F4F< /color><!--暗瓦灰色 --> 

 

 < color name="darkslategrey">#2F4F4F< /color><!--暗瓦灰色 -->  

 < color name="seagreen">#2E8B57< /color>< !--海绿色 -->  

 < color name="forestgreen">#228B22< /color><!--森林绿 -->  

 < color name="lightseagreen">#20B2AA< /color><!--亮海蓝色 -->  

 < color name="dodgerblue">#1E90FF< /color>< !--闪兰色 -->  

 < color name="midnightblue">#191970< /color><!--中灰兰色 --> 

 

 < color name="aqua">#00FFFF< /color>< !--浅绿色 --> 

 

 < color name="cyan">#00FFFF< /color>< !--青色 --> 

 

 < color name="springgreen">#00FF7F< /color><!--春绿色 --> 

 

 < color name="lime">#00FF00< /color>< !--酸橙色 --> 

 

 < color name="mediumspringgreen">#00FA9A</color>< !--中春绿色 --> 

 

 < color name="darkturquoise">#00CED1< /color><!--暗宝石绿 -->  

 < color name="deepskyblue">#00BFFF< /color><!--深天蓝色 -->  

 < color name="darkcyan">#008B8B< /color>< !--暗青色 -->  

 < color name="teal">#008080< /color>< !--水鸭色 -->  

 < color name="green">#008000< /color>< !--绿色 --> 

 

 < color name="darkgreen">#006400< /color>< !--暗绿色 --> 

 

 < color name="blue">#0000FF< /color>< !--蓝色 --> 

< colorname="mediumblue">#0000CD< /color>< !--中兰色 --> 

< colorname="darkblue">#00008B< /color>< !--暗蓝色 --> 

< colorname="navy">#000080< /color>< !--海军色 --> 

 

 < color name="black">#000000< /color>< !--黑色 --> 

 

 < /resources>

android ListView详解 

  在 android开发中ListView是比较常用的组件,它以列表的形式展示具体内容,并且能够根据数据的长度自适应显示。抽空把对 ListView 的使用做了整理,并写了个小例子,如下图。

 

 

 列表的显示需要三个元素:

1.ListVeiw 用来展示列表的View。

2.适配器 用来把数据映射到ListView 上的中介。

3.数据    具体的将被映射的字符串,图片,或者基本组件。

根据列表的适配器类型,列表分为三种,ArrayAdapter,SimpleAdapter和 SimpleCur sorAdapter

其中以 ArrayAdapter 最为简单,只能展示一行字。SimpleAdapter有最好的扩充性,可以自定义出各种效果。SimpleCursorAdapter可以认为是 SimpleAdapter 对数据库的简单结合,可以方面的把数据库的内容以列表的形式展示出来。

 

 我们从最简单的 ListView 开始:

 

print?

01      /**  

02      * @author allin

03      *  

04      */

05      publicclassMyListView extendsActivity {

06

 

07                     privateListView listView;  

08                     //private List<String> data = newArrayList<String>();

09                     @Override

10                     publicvoidonCreate(Bundle savedInstanceState){

11                     super.onCreate(savedInstanceState);

12         

13                     listView = newListView(this);  

14                     listView.setAdapter(new    ArrayAdapter<String>(this,android.R.layout.simple_expandable_list_item_1,getData())); 

15                     setContentView(listView);

16                     }  

17       

18       

19

 

20  privateList<String> getData(){

21           

22               List<String> data = newArrayList<String>();

23               data.add("测试数据1");

24               data.add("测试数据2");

25               data.add("测试数据3");

26               data.add("测试数据4");

28               returndata;

29               }

30               }

 

 

上面代码使用了 ArrayAdapter(Context context, int textViewResourceId,List<T>  objects)来装配数据,要装配这些数据就需要一个连接 ListView 视图对象和数组数据的适配器来两者的适配工作,ArrayAdapter的构造需要三个参数,依次为this,布局文件(注意这里的布局文件描述的是列表的每一行的布局,android.R.layout.simple_list_item_
1 是系统定义好的布局文件只显示一行文字,数据源(一个 List集合)。同时用setAdapter

()完成适配的最后工作。运行后的现实结构如下图:

 

 

 

SimpleCursorAdapter

  sdk 的解释是这样的:An easy adapter to map columns from a cursor to T extViews orImageViews defined in an XML file. You can specify which colu mns you want,which views you want to display the columns, and the XML  file that defines the appearance of theseviews。简单的说就是方便把从游标得到的数据进行列表显示,并可以把指定的列映射到对应的TextView
中。

  下面的程序是从电话簿中把联系人显示到类表中。先在通讯录中添加一个联系人作为数据库的数据。然后获得一个指向数据库的Cursor并且定义一个布局文件(当然也可以使用系统自带的)。

 

view source

抱歉!评论已关闭.