Guest User

Untitled

a guest
Jul 23rd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. <View
  2. android:id="@+id/view2"
  3. android:layout_width="59dp"
  4. android:layout_height="65dp"
  5. android:background="@drawable/lightbulb" />
  6.  
  7. final View normalView = findViewById(R.id.view2);
  8.  
  9. //Where I need to set the alpha
  10. int alphaValue = /*Some calculation*/
  11. normalView.getBackground().setAlpha(alphaValue);
  12. normalView.invalidate();
  13.  
  14. class LightbulbView extends View {
  15.  
  16. private BitmapDrawable mLightbulbDrawable;
  17. private Paint mPaint;
  18.  
  19. /*All constructors which call through to super*/
  20.  
  21. private void initialize(){
  22. mLightbulbDrawable = new BitmapDrawable(getResources(), BitmapFactory.decodeResource(getResources(), R.drawable.lightbulb));
  23. mPaint = new Paint();
  24. }
  25.  
  26. @Override
  27. protected void onDraw(Canvas canvas) {
  28. super.onDraw(canvas);
  29. mLightbulbDrawable.draw(canvas);
  30. }
  31.  
  32. /*Without this, I get an NPE when I do a getBackground on this view*/
  33. @Override
  34. public Drawable getBackground() {
  35. return mLightbulbDrawable;
  36. //return super.getBackground();
  37. }
  38. }
  39.  
  40. <ImageView
  41. android:layout_width="wrap_content"
  42. android:id="@+id/imageView1"
  43. android:layout_height="wrap_content"
  44. android:src="@drawable/lightbulb"
  45. ></ImageView>
  46.  
  47. final ImageView imageView = (ImageView) findViewById(R.id.imageView1);
  48. imageView.setAlpha(alphaValue);
  49.  
  50. <FrameLayout
  51. android:id="@+id/frameLayout1"
  52. android:layout_width="fill_parent"
  53. android:layout_height="wrap_content"
  54. >
  55. <ImageView
  56. android:layout_height="wrap_content"
  57. android:src="@drawable/lightbulb_content"
  58. android:layout_width="wrap_content"
  59. android:id="@+id/bulbContent"
  60. ></ImageView>
  61. <ImageView
  62. android:layout_height="wrap_content"
  63. android:src="@drawable/lightbulb"
  64. android:layout_width="wrap_content"
  65. android:id="@+id/bulb"
  66. ></ImageView>
  67.  
  68. </FrameLayout>
  69.  
  70. final ImageView bulbContent = (ImageView) findViewById(R.id.bulbContent);
  71. //Where I need to set the alpha
  72. int alphaValue = /*Some calculation*/
  73. normalView.getBackground().setAlpha(alphaValue);
  74. bulbContent.setAlpha(alphaValue);
Add Comment
Please, Sign In to add comment