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

Samsung Galaxy S8 battery life test: blatantly reduced compared to S7!

Samsung S8/S8+ has just been released, and the bat...

What does pua man mean in internet slang?

I believe everyone is familiar with " PUA &q...

Running away after mating, is it to survive? | Nature Trumpet

Welcome to the seventh issue of the Nature Trumpe...

Review of NetEase Cloud Classroom's fission activity

NetEase Cloud Classroom held another fission acti...

Chubby Bird: I'm not fat, I just have big breasts

My favorite animal literature writer, Vi Bianchi,...

E-commerce operations: Marketing planning to create hot products

What is a hot item? Simply put, it is the best-se...

Square’s App Visibility Principles

[[147070]] background Over the past five years, o...