Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <View
- android:id="@+id/view2"
- android:layout_width="59dp"
- android:layout_height="65dp"
- android:background="@drawable/lightbulb" />
- final View normalView = findViewById(R.id.view2);
- //Where I need to set the alpha
- int alphaValue = /*Some calculation*/
- normalView.getBackground().setAlpha(alphaValue);
- normalView.invalidate();
- class LightbulbView extends View {
- private BitmapDrawable mLightbulbDrawable;
- private Paint mPaint;
- /*All constructors which call through to super*/
- private void initialize(){
- mLightbulbDrawable = new BitmapDrawable(getResources(), BitmapFactory.decodeResource(getResources(), R.drawable.lightbulb));
- mPaint = new Paint();
- }
- @Override
- protected void onDraw(Canvas canvas) {
- super.onDraw(canvas);
- mLightbulbDrawable.draw(canvas);
- }
- /*Without this, I get an NPE when I do a getBackground on this view*/
- @Override
- public Drawable getBackground() {
- return mLightbulbDrawable;
- //return super.getBackground();
- }
- }
- <ImageView
- android:layout_width="wrap_content"
- android:id="@+id/imageView1"
- android:layout_height="wrap_content"
- android:src="@drawable/lightbulb"
- ></ImageView>
- final ImageView imageView = (ImageView) findViewById(R.id.imageView1);
- imageView.setAlpha(alphaValue);
- <FrameLayout
- android:id="@+id/frameLayout1"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- >
- <ImageView
- android:layout_height="wrap_content"
- android:src="@drawable/lightbulb_content"
- android:layout_width="wrap_content"
- android:id="@+id/bulbContent"
- ></ImageView>
- <ImageView
- android:layout_height="wrap_content"
- android:src="@drawable/lightbulb"
- android:layout_width="wrap_content"
- android:id="@+id/bulb"
- ></ImageView>
- </FrameLayout>
- final ImageView bulbContent = (ImageView) findViewById(R.id.bulbContent);
- //Where I need to set the alpha
- int alphaValue = /*Some calculation*/
- normalView.getBackground().setAlpha(alphaValue);
- bulbContent.setAlpha(alphaValue);
Add Comment
Please, Sign In to add comment