개발/Android
[안드로이드/java] BottomSheet 스크롤 할 때 slideOffset 으로 background 조절
뚀니 Ddoeni
2019. 4. 13. 22:19
728x90
int colorFromTop = getResources().getColor(R.color.downy);
int colorFromBottom = getResources().getColor(R.color.scooter);
int colorTo = getResources().getColor(R.color.transparent);
int[] colors = {interpolateColor(slideOffset, colorFromTop, colorTo), interpolateColor(slideOffset, colorFromBottom, colorTo)};
GradientDrawable gd = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, colors);
gd.setCornerRadii(new float[]{radius, radius, radius, radius, 0, 0, 0, 0});
act.layoutIntroPeek.setBackground(gd);
background 가 gradient 도 있고 상단 corner도 있어서 작업하였다.
참조한 코드
https://android.jlelse.eu/choreographic-animations-with-androids-bottomsheet-fef06e6ecb81
Choreographic animations with Android’s BottomSheet
It has been a while since Google included bottom sheets into its design support library allowing developers to integrate it into their…
android.jlelse.eu
private int interpolateColor(float fraction, int startValue, int endValue) {
int startA = (startValue >> 24) & 0xff;
int startR = (startValue >> 16) & 0xff;
int startG = (startValue >> 8) & 0xff;
int startB = startValue & 0xff;
int endA = (endValue >> 24) & 0xff;
int endR = (endValue >> 16) & 0xff;
int endG = (endValue >> 8) & 0xff;
int endB = endValue & 0xff;
return ((startA + (int) (fraction * (endA - startA))) << 24) |
((startR + (int) (fraction * (endR - startR))) << 16) |
((startG + (int) (fraction * (endG - startG))) << 8) |
((startB + (int) (fraction * (endB - startB))));
}
300x250