我正在尝试在 zomato 应用程序中实现过滤器之类的东西,在选择过滤器时,第一个屏幕移动仅显示第一个屏幕的一部分和整个第二个屏幕,我们可以在其中选择过滤器的类型,选择后可以为我们提供所有移动第一个和第二个屏幕后的过滤器类型。
我所做的是我将内部屏幕(过滤器类型和过滤器选项)作为两个不可见的相对布局,然后我滑动它们并通过更改其布局参数的边距并请求布局使它们可见。
在显示第三个屏幕(过滤器选项)时,即使我提供了正确的边距,第二个屏幕也不可见。
任何人都可以帮忙吗?
编辑代码:
私有类 SlidingAnimation 扩展动画 {
private float mainViewStartX, mainViewEndX;
private float sideViewFromX, sideViewToX;
private float sideView2FromX,sideView2ToX;
private View slideInView,slideOutView,slideInView2;
public SlidingAnimation(float fromX, float toX, float sideViewFromX,
float sideViewToX,float sideView2FromX,float sideView2ToX, int duration,View slideInView,View slideOutView,View slideInView2) {
setDuration(duration);
this.slideInView = slideInView;
this.slideOutView = slideOutView;
this.slideInView2 = slideInView2;
mainViewEndX = toX;
mainViewStartX = fromX;
slideOutViewLayoutParams = (LayoutParams) slideOutView.getLayoutParams();
this.sideViewFromX = sideViewFromX;
this.sideViewToX = sideViewToX;
slideInViewLayoutParams = (LayoutParams) slideInView.getLayoutParams();
if(slideInView2!=null){
Log.w(null,"Side View two also exists");
this.sideView2FromX = sideView2FromX ;
this.sideView2ToX = sideView2ToX;
slideInView2LayoutParams = (LayoutParams)slideInView2.getLayoutParams();
}
}
@SuppressLint("NewApi")
@Override
protected void applyTransformation(float interpolatedTime,
Transformation t) {
super.applyTransformation(interpolatedTime, t);
if (interpolatedTime < 1.0f) {
// Applies a Smooth Transition that starts fast but ends slowly
if(slideInView2==null){
slideOutViewLayoutParams.rightMargin = (int) (mainViewStartX + ((mainViewEndX - mainViewStartX) * (Math
.pow(interpolatedTime - 1, 5) + 1)));
slideInViewLayoutParams.rightMargin = (int) (sideViewFromX - ((sideViewFromX-sideViewToX) * (Math
.pow(interpolatedTime - 1, 5) + 1)));
slideOutViewLayoutParams.leftMargin = (int)- mainViewEndX;
slideInView.requestLayout();
slideOutView.requestLayout();
Log.w(null,"Slide Out Right Margin:"+slideOutViewLayoutParams.rightMargin);
Log.w(null,"Slide Out Left Margin:"+slideOutViewLayoutParams.leftMargin);
Log.w(null,"Slide In Left Margin:"+slideInViewLayoutParams.leftMargin);
}
else{
slideOutViewLayoutParams.rightMargin = (int) (mainViewStartX + ((mainViewEndX - mainViewStartX) * (Math
.pow(interpolatedTime - 1, 5) + 1)));
slideInViewLayoutParams.rightMargin = (int) (sideViewFromX + ((sideViewToX-sideViewFromX) * (Math
.pow(interpolatedTime - 1, 5) + 1)));
slideOutViewLayoutParams.leftMargin = (int)- mainViewEndX;
slideInViewLayoutParams.leftMargin = (int)-sideViewToX;
slideInView2LayoutParams.rightMargin = (int) (sideView2FromX - ((sideView2FromX-sideView2ToX) * (Math
.pow(interpolatedTime - 1, 5) + 1)));
slideOutView.requestLayout();
slideInView.requestLayout();
slideInView2.requestLayout();
Log.w(null,"Slide Out Right Margin:"+slideOutViewLayoutParams.rightMargin);
Log.w(null,"Slide Out Left Margin:"+slideOutViewLayoutParams.leftMargin);
Log.w(null,"Slide In Left Margin:"+slideInViewLayoutParams.leftMargin);
Log.w(null,"Slide In Right Margin:"+slideInViewLayoutParams.rightMargin);
Log.w(null,"Slide In View 2 Right Margin:"+slideInView2LayoutParams.rightMargin);
}
}
}
}
来电:
SlidingAnimation open = new SlidingAnimation(-width+dpToPx(45), width - dpToPx(45/2), 0,width-dpToPx(45),-width+dpToPx(45),0,1000,filterTypeLayout, selectBusLayout,filterOptionLayout) ;