| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
package com.android.test.uibench; |
| 17 |
|
| 18 |
import android.animation.PropertyValuesHolder; |
| 19 |
import android.animation.ValueAnimator; |
| 20 |
import android.graphics.Color; |
| 21 |
import android.os.Bundle; |
| 22 |
import androidx.appcompat.app.AppCompatActivity; |
| 23 |
import android.util.DisplayMetrics; |
| 24 |
import android.view.View; |
| 25 |
import android.view.ViewGroup.LayoutParams; |
| 26 |
import android.widget.FrameLayout; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
public class ResizeHWLayerActivity extends AppCompatActivity { |
| 32 |
|
| 33 |
@Override |
| 34 |
protected void onCreate(Bundle savedInstanceState) { |
| 35 |
super.onCreate(savedInstanceState); |
| 36 |
DisplayMetrics metrics = getResources().getDisplayMetrics(); |
| 37 |
int width = metrics.widthPixels; |
| 38 |
int height = metrics.heightPixels; |
| 39 |
View child = new View(this); |
| 40 |
child.setBackgroundColor(Color.BLUE); |
| 41 |
child.setLayoutParams(new FrameLayout.LayoutParams(width, height)); |
| 42 |
child.setLayerType(View.LAYER_TYPE_HARDWARE, null); |
| 43 |
PropertyValuesHolder pvhWidth = PropertyValuesHolder.ofInt("width", width, 1); |
| 44 |
PropertyValuesHolder pvhHeight = PropertyValuesHolder.ofInt("height", height, 1); |
| 45 |
final LayoutParams params = child.getLayoutParams(); |
| 46 |
ValueAnimator animator = ValueAnimator.ofPropertyValuesHolder(pvhWidth, pvhHeight); |
| 47 |
animator.setRepeatMode(ValueAnimator.REVERSE); |
| 48 |
animator.setRepeatCount(ValueAnimator.INFINITE); |
| 49 |
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { |
| 50 |
@Override |
| 51 |
public void onAnimationUpdate(ValueAnimator valueAnimator) { |
| 52 |
params.width = (Integer)valueAnimator.getAnimatedValue("width"); |
| 53 |
params.height = (Integer)valueAnimator.getAnimatedValue("height"); |
| 54 |
child.requestLayout(); |
| 55 |
} |
| 56 |
}); |
| 57 |
animator.start(); |
| 58 |
setContentView(child); |
| 59 |
} |
| 60 |
} |