/
Practice04Alpha.java
46 lines (35 loc) · 1.26 KB
/
Practice04Alpha.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package com.geekholt.practiceui.view.lesson5;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import androidx.annotation.Nullable;
import com.geekholt.practiceui.R;
public class Practice04Alpha extends RelativeLayout {
Button animateBt;
ImageView imageView;
public Practice04Alpha(Context context) {
super(context);
}
public Practice04Alpha(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public Practice04Alpha(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
animateBt = (Button) findViewById(R.id.animateBt);
imageView = (ImageView) findViewById(R.id.imageView);
animateBt.setOnClickListener(new OnClickListener() {
@Override
public void onClick(final View v) {
// TODO 在这里处理点击事件,通过 View.animate().alpha() 来改变 View 的透明度
imageView.animate().alpha(0.8f);
}
});
}
}