Advertisement
Guest User

Untitled

a guest
Jul 29th, 2015
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. public void addToUI(final Context con) {
  2. myactivity.runOnUiThread(new Runnable() {
  3. @Override
  4. public void run() {
  5. MainFrame main = new MainFrame(con);
  6. main.backgroundColor(0, 82, 255, 0.5);
  7.  
  8. MainFrame test = new MainFrame(con);
  9. test.backgroundColor(215, 255, 4, 1);
  10. test.parameters.height = 100;
  11.  
  12. main.addView(test,test.parameters);
  13. myactivity.addContentView(main, main.parameters);
  14. }
  15. }
  16. }
  17.  
  18. public class MainFrame extends FrameLayout {
  19. public FrameLayout.LayoutParams parameters = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
  20. public MainFrame(Context con) {
  21. this(con, null);
  22. }
  23. public MainFrame(Context context, AttributeSet attrs){
  24. this(context, attrs, 0);
  25. }
  26. public MainFrame(Context context, AttributeSet attrs, int defStyle){
  27. super(context, attrs, defStyle);
  28. }
  29.  
  30. //This seams to keep have the same opacity as the parent
  31. public void backgroundColor(int red, int green, int blue, double alphaa) {
  32. this.setBackgroundColor(Color.rgb(red, green, blue));
  33. final AlphaAnimation alpha = new AlphaAnimation((float)alphaa, (float)alphaa);
  34. alpha.setDuration(0);
  35. alpha.setFillAfter(true);
  36. this.startAnimation(alpha);
  37. //this.animate().alpha((float)alphaa).setDuration(0).start();
  38.  
  39. }
  40.  
  41. public void backgroundColor(int red, int green, int blue) {
  42. this.setBackgroundColor(Color.rgb(red, green, blue));
  43. }
  44.  
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement