Guest User

Untitled

a guest
Jan 20th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. public class MyTabView extends RelativeLayout{
  2. public MyTabView(Context context) {
  3. super(context);
  4.  
  5. ImageView imageView = new ImageView(context);
  6. imageView.setImageResource(R.drawable.icon);
  7. imageView.setId(1);
  8.  
  9. //may also want to set a scaleType on the imageView
  10.  
  11. LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
  12. params.addRule(RelativeLayout.CENTER_HORIZONTAL);
  13. imageView.setLayoutParams(params);
  14.  
  15. this.addView(imageView);
  16.  
  17. TextView textView = new TextView(context);
  18. textView.setText("some text");
  19. params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
  20. params.addRule(RelativeLayout.CENTER_HORIZONTAL);
  21. params.addRule(RelativeLayout.BELOW, 1);
  22. textView.setLayoutParams(params);
  23. this.addView(textView);
  24. }
  25. }
Add Comment
Please, Sign In to add comment