挑战:ViewPager的自定义动画.更改所选元素的高度(查看折页) [英] Challenge: Custom Animation of ViewPager. Change height of chosen elements (View fold)
问题描述
我目前正在研究在ViewPager中切换页面之间的自定义动画.当我向左滑动时,View向左移动,而从它的下方,新View移到了前面.我想制作一个视图,该视图向左移动(我配置了)以像下面的图像一样缩小:
I am currently working on custom animation between switching pages in ViewPager. When I slide to the left, View is moving to the left and from below of it new View is coming to the front. I would like to make the view, that moves to the left (that I dispose) to shrink like on the folowing images:
在第二张和第三张图像上,我没有想象新的View出现在最前面,但是我认为这不是必需的.您是否知道如何修改代码?
我想更改TableLayout,RelativeLayout和FrameLayout的高度,并保持两个TextView的高度.另外,我还必须更改整个视图的X位置.
我期待您的创意答案(代码).下面,我附上我的动画代码.
On the second and third image I didn't picture new View coming to the front, but I think it wasn't necessary. Do you have any idea how can I modify the code?
I would like to change height of TableLayout, RelativeLayout and FrameLayout and keep the height of both TextViews. Also I would have to change X-position of the whole View.
I am looking forward for your creative answers (code). Below I attach my code for the animation.
import android.view.View;
import android.widget.RelativeLayout;
import android.annotation.SuppressLint;
import android.support.v4.view.ViewPager.PageTransformer;
public class DepthPageTransformer implements PageTransformer {
private static float MIN_SCALE = 0.75f;
@SuppressLint("NewApi")
public void transformPage(View view, float position) {
int pageWidth = view.getWidth();
if (position < -1) { // [-Infinity,-1)
// This page is way off-screen to the left.
view.setAlpha(0);
} else if (position <= 0) { // [-1,0]
// Use the default slide transition when moving to the left page
view.setTranslationX(0);
view.setScaleX(1);
view.setScaleY(1);
//float scaleFactor = (1 - Math.abs(position));
//WHAT TO PUT HERE TO ARCHIVE MY GOAL??
//This is how I can get particular layouts:
// RelativeLayout relativeLayout = (RelativeLayout) view.findViewById(R.id.fragment_object_canvas_RelativeLayout1);
//relativeLayout.setScaleX(scaleFactor);
//relativeLayout.setScaleY(scaleFactor);
} else if (position <= 1) { // (0,1]
// Fade the page out.
view.setAlpha(1 - position);
// Counteract the default slide transition
view.setTranslationX(pageWidth * -position);
//view.setRotation(1 - (position*360));
// Scale the page down (between MIN_SCALE and 1)
float scaleFactor = MIN_SCALE
+ (1 - MIN_SCALE) * (1 - Math.abs(position));
view.setScaleX(scaleFactor);
view.setScaleY(scaleFactor);
} else { // (1,+Infinity]
// This page is way off-screen to the right.
view.setAlpha(0);
}
}
}
更新:
我可以使用以下代码在整个View的高度上进行操作(目前只能执行此操作):
I can manipulate with height of whole View (for now I can do only this) with the following code:
LinearLayout relativeLayout = (LinearLayout) view.findViewById(R.id.fragment_object_canvas_linearLayout1);
relativeLayout.setLayoutParams(new FrameLayout.LayoutParams(relativeLayout.getWidth(), NEW_HEIGHT_HERE)));
但是,我不确定应该将什么放入NEW_HEIGHT_HERE变量中以使其完全起作用...
However, I am not sure what should I put into NEW_HEIGHT_HERE variable to make it work corectly...
推荐答案
尝试使用位置浮动变量. 获取布局的高度并...:
try to work with a position float variable. Get the height of your layout and...:
relativeLayout.setLayoutParams(....,position*height+height)
这篇关于挑战:ViewPager的自定义动画.更改所选元素的高度(查看折页)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!