Android com.daimajia.slider.library.SliderLayout 去掉底部半透明標題背景
阿新 • • 發佈:2019-01-12
com.daimajia.slider.library.SliderLayout 是挺好用的輪播圖控制元件,但是底部灰色背景有時候用不到,所以得去掉。
sliderLayout.setCustomAnimation(new DescriptionAnimation()); 這個方法是設定灰色背景動畫
我們重新寫一個類DescriptionAnimation1,內容同DescriptionAnimation,
import android.view.View; import com.daimajia.slider.library.Animations.BaseAnimationInterface;import com.daimajia.slider.library.R; import com.nineoldandroids.animation.ObjectAnimator; import com.nineoldandroids.animation.ValueAnimator; import com.nineoldandroids.view.ViewHelper; /** * A demo class to show how to use {@link com.daimajia.slider.library.Animations.BaseAnimationInterface} * to make your custom animation in {@link com.daimajia.slider.library.Tricks.ViewPagerEx.PageTransformer} action. */ public class DescriptionAnimation1 implements BaseAnimationInterface { @Override public void onPrepareCurrentItemLeaveScreen(View current) { View descriptionLayout = current.findViewById(R.id.description_layout);if(descriptionLayout!=null){ current.findViewById(R.id.description_layout).setVisibility(View.INVISIBLE); } } /** * When next item is coming to show, let's hide the description layout. * @param next */ @Override public void onPrepareNextItemShowInScreen(View next) { View descriptionLayout = next.findViewById(R.id.description_layout); if(descriptionLayout!=null){ next.findViewById(R.id.description_layout).setVisibility(View.INVISIBLE); } } @Override public void onCurrentItemDisappear(View view) { } /** * When next item show in ViewPagerEx, let's make an animation to show the * description layout. * @param view */ @Override public void onNextItemAppear(View view) { View descriptionLayout = view.findViewById(R.id.description_layout); if(descriptionLayout!=null){ float layoutY = ViewHelper.getY(descriptionLayout); view.findViewById(R.id.description_layout).setVisibility(View.GONE); ValueAnimator animator = ObjectAnimator.ofFloat( descriptionLayout,"y",layoutY + descriptionLayout.getHeight(), layoutY).setDuration(500); animator.start(); } } }
紅色程式碼,把背景隱藏掉就行了,然後 sliderLayout.setCustomAnimation(new DescriptionAnimation1());