关键词随机飞入飞出效果

布局文件

[html]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     android:orientation="vertical" >  
  6.   
  7.     <com.hnxiaohu.huamu.widget.KeywordsFlow  
  8.         android:id="@+id/keywordsflow_Layout"  
  9.         android:layout_width="match_parent"  
  10.         android:layout_height="wrap_content"  
  11.         android:layout_above="@+id/button1"  
  12.         android:layout_alignParentTop="true" >  
  13.   
  14.     </com.hnxiaohu.huamu.widget.KeywordsFlow>  
  15.   
  16.     <Button  
  17.         android:id="@+id/button1"  
  18.         android:layout_width="wrap_content"  
  19.         android:layout_height="wrap_content"  
  20.         android:layout_alignParentBottom="true"  
  21.         android:layout_alignParentLeft="true"  
  22.         android:onClick="onClick"  
  23.         android:text="飞入" />  
  24.   
  25.     <Button  
  26.         android:id="@+id/button2"  
  27.         android:layout_width="wrap_content"  
  28.         android:layout_height="wrap_content"  
  29.         android:layout_alignParentBottom="true"  
  30.         android:layout_toRightOf="@+id/button1"  
  31.         android:onClick="onClick"  
  32.         android:text="飞出" />  
  33.   
  34.   
  35. </RelativeLayout>  


使用示例

[java]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. package com.hnxiaohu.huamu.ui;  
  2.   
  3. import java.util.Random;  
  4.   
  5. import android.app.Activity;  
  6. import android.os.Bundle;  
  7. import android.view.View;  
  8. import android.view.View.OnClickListener;  
  9. import android.widget.TextView;  
  10. import android.widget.Toast;  
  11.   
  12. import com.hnxiaohu.huamu.R;  
  13. import com.hnxiaohu.huamu.widget.KeywordsFlow;  
  14.   
  15.   
  16. public class KeywordsFlowDemo extends Activity implements OnClickListener {  
  17.     public static final String[] keywords = { "国贸360""人民路""大石桥""新通桥",  
  18.             "紫荆山""医学院""二七广场""碧沙岗""凯旋门""居易国际""百货大楼""体育馆""沙门村",  
  19.             "刘庄""陈寨""科技市场""火车站" };  
  20.     public static final String[] keywords2 = { "火锅""小吃""咖啡""电影院""KTV",  
  21.             "茶馆""足浴""按摩""超市""银行""酒店""超市""豫菜""川菜""蛋糕店""医院",  
  22.             "面包店""商场""书店""烧烤""海鲜""清真" };  
  23.     private KeywordsFlow keywordsFlow;  
  24.   
  25.     public void onCreate(Bundle savedInstanceState) {  
  26.         super.onCreate(savedInstanceState);  
  27.         setContentView(R.layout.keywordsflow);  
  28.   
  29.         keywordsFlow = (KeywordsFlow) findViewById(R.id.keywordsflow_Layout);  
  30.         keywordsFlow.setDuration(800l);  
  31.         keywordsFlow.setOnClickListener(this);  
  32.     }  
  33.     // 填充关键词  
  34.     private void feedKeywordsFlow(KeywordsFlow keywordsFlow, String[] arr) {  
  35.         Random random = new Random();  
  36.         for (int i = 0; i < KeywordsFlow.MAX; i++) {  
  37.             int ran = random.nextInt(arr.length);  
  38.             String tmp = arr[ran];  
  39.             keywordsFlow.feedKeyword(tmp);  
  40.         }  
  41.     }  
  42.   
  43.     @Override  
  44.     public void onClick(View v) {  
  45.           
  46.         if(v.getId()==R.id.button1){  
  47.             keywordsFlow.rubKeywords();  
  48.             feedKeywordsFlow(keywordsFlow, keywords);  
  49.             keywordsFlow.go2Show(KeywordsFlow.ANIMATION_IN);  
  50.             return;  
  51.         }  
  52.           
  53.         if(v.getId()==R.id.button2){  
  54.             keywordsFlow.rubKeywords();  
  55.             feedKeywordsFlow(keywordsFlow, keywords2);  
  56.             keywordsFlow.go2Show(KeywordsFlow.ANIMATION_OUT);  
  57.             return;  
  58.         }  
  59.           
  60.         if(v instanceof TextView){  
  61.             String keyword = ((TextView) v).getText().toString();  
  62.             Toast.makeText(getApplication(), keyword, Toast.LENGTH_SHORT).show();  
  63.             return;  
  64.         }  
  65.   
  66.     }  
  67.   
  68. }  


自定义View

[java]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. package com.hnxiaohu.huamu.widget;  
  2.   
  3. import java.util.LinkedList;  
  4. import java.util.Random;  
  5. import java.util.Vector;  
  6.   
  7. import android.content.Context;  
  8. import android.graphics.Paint;  
  9. import android.util.AttributeSet;  
  10. import android.util.TypedValue;  
  11. import android.view.Gravity;  
  12. import android.view.View;  
  13. import android.view.ViewTreeObserver.OnGlobalLayoutListener;  
  14. import android.view.animation.AlphaAnimation;  
  15. import android.view.animation.Animation;  
  16. import android.view.animation.Animation.AnimationListener;  
  17. import android.view.animation.AnimationSet;  
  18. import android.view.animation.AnimationUtils;  
  19. import android.view.animation.Interpolator;  
  20. import android.view.animation.ScaleAnimation;  
  21. import android.view.animation.TranslateAnimation;  
  22. import android.widget.FrameLayout;  
  23. import android.widget.TextView;  
  24.   
  25. /** 
  26.  *关键词飞入和飞出动画效果 
  27.  */  
  28. public class KeywordsFlow extends FrameLayout implements OnGlobalLayoutListener {  
  29.     public static final int IDX_X = 0;  
  30.     public static final int IDX_Y = 1;  
  31.     public static final int IDX_TXT_LENGTH = 2;  
  32.     public static final int IDX_DIS_Y = 3;  
  33.     /** 由外至内的动画。 */  
  34.     public static final int ANIMATION_IN = 1;  
  35.     /** 由内至外的动画。 */  
  36.     public static final int ANIMATION_OUT = 2;  
  37.     /** 位移动画类型:从外围移动到坐标点。 */  
  38.     public static final int OUTSIDE_TO_LOCATION = 1;  
  39.     /** 位移动画类型:从坐标点移动到外围。 */  
  40.     public static final int LOCATION_TO_OUTSIDE = 2;  
  41.     /** 位移动画类型:从中心点移动到坐标点。 */  
  42.     public static final int CENTER_TO_LOCATION = 3;  
  43.     /** 位移动画类型:从坐标点移动到中心点。 */  
  44.     public static final int LOCATION_TO_CENTER = 4;  
  45.     public static final long ANIM_DURATION = 800l;  
  46.     public static final int MAX = 10;  
  47.     public static final int TEXT_SIZE_MAX = 25;  
  48.     public static final int TEXT_SIZE_MIN = 15;  
  49.     private OnClickListener itemClickListener;  
  50.     private static Interpolator interpolator;  
  51.     private static AlphaAnimation animAlpha2Opaque;  
  52.     private static AlphaAnimation animAlpha2Transparent;  
  53.     private static ScaleAnimation animScaleLarge2Normal, animScaleNormal2Large,  
  54.             animScaleZero2Normal, animScaleNormal2Zero;  
  55.     /** 存储显示的关键字。 */  
  56.     private Vector<String> vecKeywords;  
  57.     private int width, height;  
  58.     /** 
  59.      * go2Show()中被赋值为true,标识开发人员触发其开始动画显示。<br/> 
  60.      * 本标识的作用是防止在填充keywrods未完成的过程中获取到width和height后提前启动动画。<br/> 
  61.      * 在show()方法中其被赋值为false。<br/> 
  62.      * 真正能够动画显示的另一必要条件:width 和 height不为0。<br/> 
  63.      */  
  64.     private boolean enableShow;  
  65.     private Random random;  
  66.     /** 
  67.      * @see ANIMATION_IN 
  68.      * @see ANIMATION_OUT 
  69.      * @see OUTSIDE_TO_LOCATION 
  70.      * @see LOCATION_TO_OUTSIDE 
  71.      * @see LOCATION_TO_CENTER 
  72.      * @see CENTER_TO_LOCATION 
  73.      * */  
  74.     private int txtAnimInType, txtAnimOutType;  
  75.     /** 最近一次启动动画显示的时间。 */  
  76.     private long lastStartAnimationTime;  
  77.     /** 动画运行时间。 */  
  78.     private long animDuration;  
  79.   
  80.     public KeywordsFlow(Context context, AttributeSet attrs, int defStyle) {  
  81.         super(context, attrs, defStyle);  
  82.         init();  
  83.     }  
  84.   
  85.     public KeywordsFlow(Context context, AttributeSet attrs) {  
  86.         super(context, attrs);  
  87.         init();  
  88.     }  
  89.   
  90.     public KeywordsFlow(Context context) {  
  91.         super(context);  
  92.         init();  
  93.     }  
  94.   
  95.     private void init() {  
  96.         lastStartAnimationTime = 0l;  
  97.         animDuration = ANIM_DURATION;  
  98.         random = new Random();  
  99.         vecKeywords = new Vector<String>(MAX);  
  100.         getViewTreeObserver().addOnGlobalLayoutListener(this);  
  101.         interpolator = AnimationUtils.loadInterpolator(getContext(),  
  102.                 android.R.anim.decelerate_interpolator);  
  103.         animAlpha2Opaque = new AlphaAnimation(0.0f, 1.0f);  
  104.         animAlpha2Transparent = new AlphaAnimation(1.0f, 0.0f);  
  105.         animScaleLarge2Normal = new ScaleAnimation(2121);  
  106.         animScaleNormal2Large = new ScaleAnimation(1212);  
  107.         animScaleZero2Normal = new ScaleAnimation(0101);  
  108.         animScaleNormal2Zero = new ScaleAnimation(1010);  
  109.     }  
  110.   
  111.     public long getDuration() {  
  112.         return animDuration;  
  113.     }  
  114.   
  115.     public void setDuration(long duration) {  
  116.         animDuration = duration;  
  117.     }  
  118.   
  119.     public boolean feedKeyword(String keyword) {  
  120.         boolean result = false;  
  121.         if (vecKeywords.size() < MAX) {  
  122.             result = vecKeywords.add(keyword);  
  123.         }  
  124.         return result;  
  125.     }  
  126.   
  127.     /** 
  128.      * 开始动画显示。<br/> 
  129.      * 之前已经存在的TextView将会显示退出动画。<br/> 
  130.      *  
  131.      * @return 正常显示动画返回true;反之为false。返回false原因如下:<br/> 
  132.      *         1.时间上不允许,受lastStartAnimationTime的制约;<br/> 
  133.      *         2.未获取到width和height的值。<br/> 
  134.      */  
  135.     public boolean go2Show(int animType) {  
  136.         if (System.currentTimeMillis() - lastStartAnimationTime > animDuration) {  
  137.             enableShow = true;  
  138.             if (animType == ANIMATION_IN) {  
  139.                 txtAnimInType = OUTSIDE_TO_LOCATION;  
  140.                 txtAnimOutType = LOCATION_TO_CENTER;  
  141.             } else if (animType == ANIMATION_OUT) {  
  142.                 txtAnimInType = CENTER_TO_LOCATION;  
  143.                 txtAnimOutType = LOCATION_TO_OUTSIDE;  
  144.             }  
  145.             disapper();  
  146.             boolean result = show();  
  147.             return result;  
  148.         }  
  149.         return false;  
  150.     }  
  151.   
  152.     private void disapper() {  
  153.         int size = getChildCount();  
  154.         for (int i = size - 1; i >= 0; i--) {  
  155.             final TextView txt = (TextView) getChildAt(i);  
  156.             if (txt.getVisibility() == View.GONE) {  
  157.                 removeView(txt);  
  158.                 continue;  
  159.             }  
  160.             FrameLayout.LayoutParams layParams = (LayoutParams) txt  
  161.                     .getLayoutParams();  
  162.             // Log.d("ANDROID_LAB", txt.getText() + " leftM=" +  
  163.             // layParams.leftMargin + " topM=" + layParams.topMargin  
  164.             // + " width=" + txt.getWidth());  
  165.             int[] xy = new int[] { layParams.leftMargin, layParams.topMargin,  
  166.                     txt.getWidth() };  
  167.             AnimationSet animSet = getAnimationSet(xy, (width >> 1),  
  168.                     (height >> 1), txtAnimOutType);  
  169.             txt.startAnimation(animSet);  
  170.             animSet.setAnimationListener(new AnimationListener() {  
  171.                 public void onAnimationStart(Animation animation) {  
  172.                 }  
  173.   
  174.                 public void onAnimationRepeat(Animation animation) {  
  175.                 }  
  176.   
  177.                 public void onAnimationEnd(Animation animation) {  
  178.                     txt.setOnClickListener(null);  
  179.                     txt.setClickable(false);  
  180.                     txt.setVisibility(View.GONE);  
  181.                 }  
  182.             });  
  183.         }  
  184.     }  
  185.   
  186.     private boolean show() {  
  187.         if (width > 0 && height > 0 && vecKeywords != null  
  188.                 && vecKeywords.size() > 0 && enableShow) {  
  189.             enableShow = false;  
  190.             lastStartAnimationTime = System.currentTimeMillis();  
  191.             int xCenter = width >> 1, yCenter = height >> 1;  
  192.             int size = vecKeywords.size();  
  193.             int xItem = width / size, yItem = height / size;  
  194.             // Log.d("ANDROID_LAB", "--------------------------width=" + width +  
  195.             // " height=" + height + "  xItem=" + xItem  
  196.             // + " yItem=" + yItem + "---------------------------");  
  197.             LinkedList<Integer> listX = new LinkedList<Integer>(), listY = new LinkedList<Integer>();  
  198.             for (int i = 0; i < size; i++) {  
  199.                 // 准备随机候选数,分别对应x/y轴位置  
  200.                 listX.add(i * xItem);  
  201.                 listY.add(i * yItem + (yItem >> 2));  
  202.             }  
  203.             // TextView[] txtArr = new TextView[size];  
  204.             LinkedList<TextView> listTxtTop = new LinkedList<TextView>();  
  205.             LinkedList<TextView> listTxtBottom = new LinkedList<TextView>();  
  206.             for (int i = 0; i < size; i++) {  
  207.                 String keyword = vecKeywords.get(i);  
  208.                 // 随机颜色  
  209.                 int ranColor = 0xff000000 | random.nextInt(0x0077ffff);  
  210.                 // 随机位置,糙值  
  211.                 int xy[] = randomXY(random, listX, listY, xItem);  
  212.                 // 随机字体大小  
  213.                 int txtSize = TEXT_SIZE_MIN  
  214.                         + random.nextInt(TEXT_SIZE_MAX - TEXT_SIZE_MIN + 1);  
  215.                 // 实例化TextView  
  216.                 final TextView txt = new TextView(getContext());  
  217.                 txt.setOnClickListener(itemClickListener);  
  218.                 txt.setText(keyword);  
  219.                 txt.setTextColor(ranColor);  
  220.                 txt.setTextSize(TypedValue.COMPLEX_UNIT_SP, txtSize);  
  221.                 txt.setShadowLayer(2220xff696969);  
  222.                 txt.setGravity(Gravity.CENTER);  
  223.                 // 获取文本长度  
  224.                 Paint paint = txt.getPaint();  
  225.                 int strWidth = (int) Math.ceil(paint.measureText(keyword));  
  226.                 xy[IDX_TXT_LENGTH] = strWidth;  
  227.                 // 第一次修正:修正x坐标  
  228.                 if (xy[IDX_X] + strWidth > width - (xItem >> 1)) {  
  229.                     int baseX = width - strWidth;  
  230.                     // 减少文本右边缘一样的概率  
  231.                     xy[IDX_X] = baseX - xItem + random.nextInt(xItem >> 1);  
  232.                 } else if (xy[IDX_X] == 0) {  
  233.                     // 减少文本左边缘一样的概率  
  234.                     xy[IDX_X] = Math.max(random.nextInt(xItem), xItem / 3);  
  235.                 }  
  236.                 xy[IDX_DIS_Y] = Math.abs(xy[IDX_Y] - yCenter);  
  237.                 txt.setTag(xy);  
  238.                 if (xy[IDX_Y] > yCenter) {  
  239.                     listTxtBottom.add(txt);  
  240.                 } else {  
  241.                     listTxtTop.add(txt);  
  242.                 }  
  243.             }  
  244.             attach2Screen(listTxtTop, xCenter, yCenter, yItem);  
  245.             attach2Screen(listTxtBottom, xCenter, yCenter, yItem);  
  246.             return true;  
  247.         }  
  248.         return false;  
  249.     }  
  250.   
  251.     /** 修正TextView的Y坐标将将其添加到容器上。 */  
  252.     private void attach2Screen(LinkedList<TextView> listTxt, int xCenter,  
  253.             int yCenter, int yItem) {  
  254.         int size = listTxt.size();  
  255.         sortXYList(listTxt, size);  
  256.         for (int i = 0; i < size; i++) {  
  257.             TextView txt = listTxt.get(i);  
  258.             int[] iXY = (int[]) txt.getTag();  
  259.             // Log.d("ANDROID_LAB", "fix[  " + txt.getText() + "  ] x:" +  
  260.             // iXY[IDX_X] + " y:" + iXY[IDX_Y] + " r2="  
  261.             // + iXY[IDX_DIS_Y]);  
  262.             // 第二次修正:修正y坐标  
  263.             int yDistance = iXY[IDX_Y] - yCenter;  
  264.             // 对于最靠近中心点的,其值不会大于yItem<br/>  
  265.             // 对于可以一路下降到中心点的,则该值也是其应调整的大小<br/>  
  266.             int yMove = Math.abs(yDistance);  
  267.             inner: for (int k = i - 1; k >= 0; k--) {  
  268.                 int[] kXY = (int[]) listTxt.get(k).getTag();  
  269.                 int startX = kXY[IDX_X];  
  270.                 int endX = startX + kXY[IDX_TXT_LENGTH];  
  271.                 // y轴以中心点为分隔线,在同一侧  
  272.                 if (yDistance * (kXY[IDX_Y] - yCenter) > 0) {  
  273.                     // Log.d("ANDROID_LAB", "compare:" +  
  274.                     // listTxt.get(k).getText());  
  275.                     if (isXMixed(startX, endX, iXY[IDX_X], iXY[IDX_X]  
  276.                             + iXY[IDX_TXT_LENGTH])) {  
  277.                         int tmpMove = Math.abs(iXY[IDX_Y] - kXY[IDX_Y]);  
  278.                         if (tmpMove > yItem) {  
  279.                             yMove = tmpMove;  
  280.                         } else if (yMove > 0) {  
  281.                             // 取消默认值。  
  282.                             yMove = 0;  
  283.                         }  
  284.                         // Log.d("ANDROID_LAB", "break");  
  285.                         break inner;  
  286.                     }  
  287.                 }  
  288.             }  
  289.             // Log.d("ANDROID_LAB", txt.getText() + " yMove=" + yMove);  
  290.             if (yMove > yItem) {  
  291.                 int maxMove = yMove - yItem;  
  292.                 int randomMove = random.nextInt(maxMove);  
  293.                 int realMove = Math.max(randomMove, maxMove >> 1) * yDistance  
  294.                         / Math.abs(yDistance);  
  295.                 iXY[IDX_Y] = iXY[IDX_Y] - realMove;  
  296.                 iXY[IDX_DIS_Y] = Math.abs(iXY[IDX_Y] - yCenter);  
  297.                 // 已经调整过前i个需要再次排序  
  298.                 sortXYList(listTxt, i + 1);  
  299.             }  
  300.             FrameLayout.LayoutParams layParams = new FrameLayout.LayoutParams(  
  301.                     FrameLayout.LayoutParams.WRAP_CONTENT,  
  302.                     FrameLayout.LayoutParams.WRAP_CONTENT);  
  303.             layParams.gravity = Gravity.LEFT | Gravity.TOP;  
  304.             layParams.leftMargin = iXY[IDX_X];  
  305.             layParams.topMargin = iXY[IDX_Y];  
  306.             addView(txt, layParams);  
  307.             // 动画  
  308.             AnimationSet animSet = getAnimationSet(iXY, xCenter, yCenter,  
  309.                     txtAnimInType);  
  310.             txt.startAnimation(animSet);  
  311.         }  
  312.     }  
  313.   
  314.     public AnimationSet getAnimationSet(int[] xy, int xCenter, int yCenter,  
  315.             int type) {  
  316.         AnimationSet animSet = new AnimationSet(true);  
  317.         animSet.setInterpolator(interpolator);  
  318.         if (type == OUTSIDE_TO_LOCATION) {  
  319.             animSet.addAnimation(animAlpha2Opaque);  
  320.             animSet.addAnimation(animScaleLarge2Normal);  
  321.             TranslateAnimation translate = new TranslateAnimation((xy[IDX_X]  
  322.                     + (xy[IDX_TXT_LENGTH] >> 1) - xCenter) << 10,  
  323.                     (xy[IDX_Y] - yCenter) << 10);  
  324.             animSet.addAnimation(translate);  
  325.         } else if (type == LOCATION_TO_OUTSIDE) {  
  326.             animSet.addAnimation(animAlpha2Transparent);  
  327.             animSet.addAnimation(animScaleNormal2Large);  
  328.             TranslateAnimation translate = new TranslateAnimation(0, (xy[IDX_X]  
  329.                     + (xy[IDX_TXT_LENGTH] >> 1) - xCenter) << 10,  
  330.                     (xy[IDX_Y] - yCenter) << 1);  
  331.             animSet.addAnimation(translate);  
  332.         } else if (type == LOCATION_TO_CENTER) {  
  333.             animSet.addAnimation(animAlpha2Transparent);  
  334.             animSet.addAnimation(animScaleNormal2Zero);  
  335.             TranslateAnimation translate = new TranslateAnimation(0,  
  336.                     (-xy[IDX_X] + xCenter), 0, (-xy[IDX_Y] + yCenter));  
  337.             animSet.addAnimation(translate);  
  338.         } else if (type == CENTER_TO_LOCATION) {  
  339.             animSet.addAnimation(animAlpha2Opaque);  
  340.             animSet.addAnimation(animScaleZero2Normal);  
  341.             TranslateAnimation translate = new TranslateAnimation(  
  342.                     (-xy[IDX_X] + xCenter), 0, (-xy[IDX_Y] + yCenter), 0);  
  343.             animSet.addAnimation(translate);  
  344.         }  
  345.         animSet.setDuration(animDuration);  
  346.         return animSet;  
  347.     }  
  348.   
  349.     /** 
  350.      * 根据与中心点的距离由近到远进行冒泡排序。 
  351.      *  
  352.      * @param endIdx 
  353.      *            起始位置。 
  354.      * @param txtArr 
  355.      *            待排序的数组。 
  356.      *  
  357.      */  
  358.     private void sortXYList(LinkedList<TextView> listTxt, int endIdx) {  
  359.         for (int i = 0; i < endIdx; i++) {  
  360.             for (int k = i + 1; k < endIdx; k++) {  
  361.                 if (((int[]) listTxt.get(k).getTag())[IDX_DIS_Y] < ((int[]) listTxt  
  362.                         .get(i).getTag())[IDX_DIS_Y]) {  
  363.                     TextView iTmp = listTxt.get(i);  
  364.                     TextView kTmp = listTxt.get(k);  
  365.                     listTxt.set(i, kTmp);  
  366.                     listTxt.set(k, iTmp);  
  367.                 }  
  368.             }  
  369.         }  
  370.     }  
  371.   
  372.     /** A线段与B线段所代表的直线在X轴映射上是否有交集。 */  
  373.     private boolean isXMixed(int startA, int endA, int startB, int endB) {  
  374.         boolean result = false;  
  375.         if (startB >= startA && startB <= endA) {  
  376.             result = true;  
  377.         } else if (endB >= startA && endB <= endA) {  
  378.             result = true;  
  379.         } else if (startA >= startB && startA <= endB) {  
  380.             result = true;  
  381.         } else if (endA >= startB && endA <= endB) {  
  382.             result = true;  
  383.         }  
  384.         return result;  
  385.     }  
  386.   
  387.     private int[] randomXY(Random ran, LinkedList<Integer> listX,  
  388.             LinkedList<Integer> listY, int xItem) {  
  389.         int[] arr = new int[4];  
  390.         arr[IDX_X] = listX.remove(ran.nextInt(listX.size()));  
  391.         arr[IDX_Y] = listY.remove(ran.nextInt(listY.size()));  
  392.         return arr;  
  393.     }  
  394.   
  395.     public void onGlobalLayout() {  
  396.         int tmpW = getWidth();  
  397.         int tmpH = getHeight();  
  398.         if (width != tmpW || height != tmpH) {  
  399.             width = tmpW;  
  400.             height = tmpH;  
  401.             show();  
  402.         }  
  403.     }  
  404.   
  405.     public Vector<String> getKeywords() {  
  406.         return vecKeywords;  
  407.     }  
  408.   
  409.     public void rubKeywords() {  
  410.         vecKeywords.clear();  
  411.     }  
  412.   
  413.     /** 直接清除所有的TextView。在清除之前不会显示动画。 */  
  414.     public void rubAllViews() {  
  415.         removeAllViews();  
  416.     }  
  417.   
  418.     public void setOnClickListener(OnClickListener listener) {  
  419.         itemClickListener = listener;  
  420.     }  

  1. }  



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值