Android application source code custom controls

Android application source code custom controls

Tools

Android

Android

Java

Eclipse

3.07MB

Source code download address: http://www.devstore.cn/code/info/679.html

Source code introduction

A small example found on the Internet is about custom controls. If you have this need, you can take it and study it.

Source code running screenshot

Run screenshot

Run screenshot

Run screenshot

Source code snippet

  1. public MyImageView(Context context, AttributeSet attrs) {
  2. super (context, attrs);
  3. // TODO Auto-generated constructor stub  
  4. int resourceId = -1;
  5. TypedArray typedArray = context.obtainStyledAttributes(attrs,
  6. R.styleable.MyImageView);
  7. ImageView iv = new ImageView(context);
  8. TextView tv = new TextView(context);
  9.   
  10. int N = typedArray.getIndexCount();
  11. for ( int i = 0; i < N; i++) {
  12. int attr = typedArray.getIndex(i);
  13.   
  14. switch (attr) {
  15. case R.styleable.MyImageView_Oriental:
  16. resourceId = typedArray.getInt(
  17. R.styleable.MyImageView_Oriental, 0);
  18. this .setOrientation(resourceId == 1 ? LinearLayout.HORIZONTAL
  19. : LinearLayout.VERTICAL);
  20. break ;
  21.   
  22. case R.styleable.MyImageView_Text:
  23. resourceId = typedArray.getResourceId(
  24. R.styleable.MyImageView_Text, 0);
  25. tv.setText(resourceId > 0 ? typedArray.getResources().getText(
  26. resourceId) : typedArray
  27. .getString(R.styleable.MyImageView_Text));
  28. break ;
  29.                   
  30.                   
  31. case R.styleable.MyImageView_Src:
  32. resourceId = typedArray.getResourceId(
  33. R.styleable.MyImageView_Src, 0);
  34. iv.setImageResource(resourceId > 0 ?resourceId:R.drawable.ic_launcher);
  35.                   
  36. break ;
  37.                   
  38. }
  39.   
  40. }
  41.   
  42. addView(iv);
  43. addView(tv);
  44. typedArray.recycle();
  45.   
  46. }

Source code download address: http://www.devstore.cn/code/info/679.html

<<:  APICloud builds an ecosystem to accelerate mobile development

>>:  iOS source code: annual calendar showing events

Recommend

Jie Xiaojie · Popular methods and techniques course videos on short videos

The course is about the techniques and methods of...

18 knowledge points about content marketing

Content seeding, this word has been on our lips f...

ClickHouse application practice and principle analysis

Course Description ClickHouse is an open source c...

A netizen posted a picture, and the comment section couldn't sit still...

Review expert: Zhang Yuhong Zhengzhou Central Hos...

101 APP operation and promotion tools you must know

1. Operate and promote the useful information web...