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

37 public account editing skills that new media people must know!

When creating content for a public account, there...

How to use human nature to attract traffic?

Today's traffic business has reached a stage ...

“The first bucket of milk tea in autumn”, will it save life or kill you?

Yesterday was the beginning of autumn, and “the f...

User operation: How to conduct user behavior analysis?

Many students are most afraid of doing open-ended...

Writing copy is not to attract attention, but to occupy your time!

The purpose of writing copy is to gain as much us...

Example analysis: How to write a product data report?

Product data reporting is an essential task for p...

Copying 100 companies? What are Xiaomi's limitations?

Two and a half years ago, I wrote an article titl...

The "traffic secret" behind Zhang's sudden popularity

The fact that "Teacher Zhang"'s con...

Operational strategy: How to effectively recall lost users?

User churn is a very troubling problem for operat...

What are the “first principles” of brand marketing?

There is a consensus in the marketing community t...

Give APP the ability to speak and let the product spread itself!

Realize user self-propagation? Why should users t...