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

Analysis of the planning of a single product live broadcast room

A classmate asked me about the gameplay of "...

What are Alibaba and JD.com’s VR+ shopping waiting for?

This April Fool's Day, the VR shopping lab (B...

How to evaluate the feed flow effect of Xiaohongshu?

Maybe many of you have no relevant experience lik...

After studying 10 big Douyin accounts, I found 8 Douyin promotion routines

Brother Xian has been feeling rather depressed la...

Content operation: Doing this is very "valuable"

What is good content? This is not a question with...

Can WeChat be used like this? Hidden WeChat operations that will open your eyes

WeChat is used every day, but do you know how man...

How to plan fission activities? 4 key nodes!

The key to planning fission activities lies in th...

A guide to traveling with your parents (happy version)! Proven and effective

During the upcoming Spring Festival holiday, many...

Four channels for APP to recall users: EDM, Push, SMS, and public account

The author of this article will share with you ho...