android 随机云标签(圆形)

举报
再见孙悟空_ 发表于 2022/01/12 22:31:46 2022/01/12
【摘要】 下面是实现的效果图: 这个适合用于选择 用户的一些兴趣标签,个性名片等。 代码: Activity package com.dyl.cloudtags; import java.util.ArrayList;import java.util.Arrays;import java.uti...

下面是实现的效果图:

这个适合用于选择 用户的一些兴趣标签,个性名片等。

代码:

Activity


  

  

  
  1. package com.dyl.cloudtags;
  2. import java.util.ArrayList;
  3. import java.util.Arrays;
  4. import java.util.Random;
  5. import android.app.Activity;
  6. import android.content.SharedPreferences;
  7. import android.os.Bundle;
  8. import android.view.View;
  9. import android.view.View.OnClickListener;
  10. import android.widget.EditText;
  11. import android.widget.ImageView;
  12. import android.widget.TextView;
  13. import android.widget.Toast;
  14. public class MainActivity extends Activity {
  15. private KeywordsFlow keywordsFlow;
  16. private String[] keywords;
  17. public static final String SEARCH_HISTORY = "search_history";
  18. private ArrayList<SearchDataPojo> searchItem;
  19. private String longhistory;
  20. private SharedPreferences sp;
  21. private ArrayList<String> history;
  22. private EditText world_shopping_search_input;
  23. private TextView world_city_refresh, clear_history;
  24. private ImageView toSearch;
  25. @Override
  26. protected void onCreate(Bundle savedInstanceState) {
  27. super.onCreate(savedInstanceState);
  28. setContentView(R.layout.activity_main);
  29. initView();
  30. initSearchHistory();
  31. refreshTags();
  32. }
  33. private void initView() {
  34. world_shopping_search_input = (EditText) findViewById(R.id.world_shopping_search_input);
  35. keywordsFlow = (KeywordsFlow) findViewById(R.id.keywordsflow);
  36. world_city_refresh = (TextView) findViewById(R.id.world_city_refresh);
  37. world_city_refresh.setOnClickListener(new OnClickListener() {
  38. @Override
  39. public void onClick(View arg0) {
  40. refreshTags();
  41. }
  42. });
  43. clear_history = (TextView) findViewById(R.id.clear_history);
  44. clear_history.setOnClickListener(new OnClickListener() {
  45. @Override
  46. public void onClick(View arg0) {
  47. clearSearchHistory();
  48. }
  49. });
  50. toSearch = (ImageView) findViewById(R.id.toSearch);
  51. toSearch.setOnClickListener(new OnClickListener() {
  52. @Override
  53. public void onClick(View arg0) {
  54. saveSearchHistory();
  55. refreshTags();
  56. }
  57. });
  58. }
  59. private void refreshTags() {
  60. initSearchHistory();
  61. keywordsFlow.setDuration(800l);
  62. keywordsFlow.setOnItemClickListener(new OnClickListener() {
  63. @Override
  64. public void onClick(View v) {
  65. String keyword = ((TextView) v).getText().toString();// 获得点击的标签
  66. world_shopping_search_input.setText(keyword);
  67. }
  68. });
  69. // 添加
  70. feedKeywordsFlow(keywordsFlow, keywords);
  71. keywordsFlow.go2Show(KeywordsFlow.ANIMATION_IN);
  72. }
  73. private static void feedKeywordsFlow(KeywordsFlow keywordsFlow, String[] arr) {
  74. Random random = new Random();
  75. for (int i = 0; i < KeywordsFlow.MAX; i++) {
  76. int ran = random.nextInt(arr.length);
  77. String tmp = arr[ran];
  78. keywordsFlow.feedKeyword(tmp);
  79. }
  80. }
  81. /**
  82. * 读取历史搜索记录
  83. */
  84. private void initSearchHistory() {
  85. sp = getSharedPreferences(MainActivity.SEARCH_HISTORY, 0);
  86. longhistory = sp.getString(MainActivity.SEARCH_HISTORY, "");
  87. if (!longhistory.equals("")) {
  88. keywords = longhistory.split(",");
  89. searchItem = new ArrayList<SearchDataPojo>();
  90. for (int i = 0; i < keywords.length; i++) {
  91. searchItem.add(new SearchDataPojo().setContent(keywords[i]));
  92. }
  93. } else {// 如果SharedPreferences没有值得话,就显示默认的数据
  94. keywords = new String[] { "口味虾", "牛蛙", "火锅", "真功夫", "料理",
  95. "密室逃", "天成房", "波比艾" };
  96. }
  97. }
  98. /*
  99. * 保存搜索记录
  100. */
  101. private void saveSearchHistory() {
  102. String text = world_shopping_search_input.getText().toString().trim();
  103. Toast.makeText(this, text, Toast.LENGTH_LONG).show();
  104. if (!text.equals("") && text != null) {
  105. if (text.length() < 1) {
  106. return;
  107. }
  108. sp = getSharedPreferences(SEARCH_HISTORY, 0);
  109. String longhistory = sp.getString(SEARCH_HISTORY, "");
  110. String[] tmpHistory = longhistory.split(",");
  111. history = new ArrayList<String>(Arrays.asList(tmpHistory));
  112. if (history.size() > 0) {
  113. int i;
  114. for (i = 0; i < history.size(); i++) {
  115. if (text.equals(history.get(i))) {
  116. history.remove(i);
  117. break;
  118. }
  119. }
  120. history.add(0, text);
  121. }
  122. if (history.size() > 0) {
  123. StringBuilder sb = new StringBuilder();
  124. for (int i = 0; i < history.size(); i++) {
  125. sb.append(history.get(i) + ",");
  126. }
  127. sp.edit().putString(SEARCH_HISTORY, sb.toString()).commit();
  128. } else {
  129. sp.edit().putString(SEARCH_HISTORY, text + ",").commit();
  130. }
  131. clear_history.setVisibility(View.VISIBLE);
  132. }
  133. }
  134. // 清除历史数据
  135. private void clearSearchHistory() {
  136. searchItem.removeAll(searchItem);
  137. sp.edit().clear().commit();
  138. Toast.makeText(this, "清除历史记录", Toast.LENGTH_LONG).show();
  139. }
  140. }

用于将控件 设置为圆形 的自定义TextView
 


  
  1. package com.dyl.cloudtags;
  2. import android.content.Context;
  3. import android.graphics.Canvas;
  4. import android.graphics.Color;
  5. import android.graphics.Paint;
  6. import android.graphics.PaintFlagsDrawFilter;
  7. import android.util.AttributeSet;
  8. import android.widget.TextView;
  9. public class CircleView extends TextView {
  10. private Paint mBgPaint = new Paint();
  11. PaintFlagsDrawFilter pfd = new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG|Paint.FILTER_BITMAP_FLAG);
  12. public CircleView(Context context, AttributeSet attrs, int defStyle) {
  13. super(context, attrs, defStyle);
  14. // TODO Auto-generated constructor stub
  15. }
  16. public CircleView(Context context, AttributeSet attrs) {
  17. super(context, attrs);
  18. // TODO Auto-generated constructor stub
  19. mBgPaint.setColor(Color.WHITE);
  20. mBgPaint.setAntiAlias(true);
  21. }
  22. public CircleView(Context context) {
  23. super(context);
  24. // TODO Auto-generated constructor stub
  25. mBgPaint.setColor(Color.WHITE);
  26. mBgPaint.setAntiAlias(true);
  27. }
  28. @Override
  29. protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
  30. // TODO Auto-generated method stub
  31. super.onMeasure(widthMeasureSpec, heightMeasureSpec);
  32. int measuredWidth = getMeasuredWidth();
  33. int measuredHeight = getMeasuredHeight();
  34. int max = Math.max(measuredWidth, measuredHeight);
  35. setMeasuredDimension(max, max);
  36. }
  37. @Override
  38. public void setBackgroundColor(int color) {
  39. // TODO Auto-generated method stub
  40. mBgPaint.setColor(color);
  41. }
  42. /**
  43. * 设置通知个数显示
  44. * @param text
  45. */
  46. public void setNotifiText(int text){
  47. // if(text>99){
  48. // String string = 99+"+";
  49. // setText(string);
  50. // return;
  51. // }
  52. setText(text+"");
  53. }
  54. @Override
  55. public void draw(Canvas canvas) {
  56. // TODO Auto-generated method stub
  57. canvas.setDrawFilter(pfd);
  58. canvas.drawCircle(getWidth()/2, getHeight()/2, Math.max(getWidth(), getHeight())/2, mBgPaint);
  59. super.draw(canvas);
  60. }
  61. }

自定义布局 用于动态生成多个 控件  核心类


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


  


  
  1. package com.dyl.cloudtags;
  2. /**
  3. * 搜索记录
  4. * @author dengyalan
  5. *
  6. */
  7. public class SearchDataPojo {
  8. private String content = "";
  9. public String getContent() {
  10. return content;
  11. }
  12. public SearchDataPojo setContent(String content) {
  13. this.content = content;
  14. return this;
  15. }
  16. }


源码下载


另外如果还有其它问题,可以加入我的qq群:Android开发经验交流群 454430053 互相学习交流。

文章来源: wukong.blog.csdn.net,作者:再见孙悟空_,版权归原作者所有,如需转载,请联系作者。

原文链接:wukong.blog.csdn.net/article/details/49281619

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。