demand:
Dynamically changed in folder BACKGROUND longitudinal fillet angle reaches fusion effect.
Methods Introduction:
Normally we only xml configuration shape drawable background in which to set the rounded background to View
For example: the layout file
<View
android:id="@+id/folder_page_view_bg"
android:layout_width="@dimen/folder_paged_view_bg_width"
android:layout_height="@dimen/folder_paged_view_bg_height"
android:layout_gravity="center"
android:background="@drawable/bg_folder_content">
</View>
drawable shape file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="@dimen/folder_bg_content_radius" />
<solid android:color="@color/folder_icon_background" />
</shape>
Such simple two-step to achieve a rounded background, but our needs are dynamically changing background rounded angles, so they need another program
1. First, we can think of to use dynamic change animation properties set the start and target angle, dynamically change the angle.
2. The need to dynamically set the background image to the View and need to dynamically change the angle of the picture
The final code is as follows:
private ValueAnimator animatorUpdateFolderBgRadius(View view , int startRadius , int endRadius){
ValueAnimator valueAnimator = ValueAnimator.ofInt(startRadius, endRadius);
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
int value = (int) animation.getAnimatedValue();
bgDrawable.setCornerRadius(value);
view.setBackground(bgDrawable);
}
});
return valueAnimator;
}
We only need to initialize
GradientDrawable bgDrawable = new GradientDrawable();