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 iReader vs. WeChat Reading Products

Books are the ladder of human progress, but paper...

Interpretation of APP advertiser behavior big data in 2017

The data shows that compared with the historical ...

10 ways to ensure your app passes Apple review!

Recently, Apple listed the ten sins on its develo...

I spent 20,000 yuan, why is there not a single conversion?

“I know that half the money I spend on advertisin...

iPhone 6 surprise new discovery: big screen

In addition to iOS 8 and OS X 10.10 beta versions,...

5 tips for brand marketing positioning!

There are many ways to position yourself, but the...

How to control costs while improving conversion effects through advertising?

For those who are new to the industry, it may be ...