Android 删除ViewFlipper中视图之间的空间
我尝试在一个ViewFlipper中制作一个包含3个视图的幻灯片动画,当我在其中切换时,会得到一个空白区域。当我试图在“移动”中更改视图时,有没有办法消除视图之间的空间,使它们看起来像是粘在一起的 以下是XML:Android 删除ViewFlipper中视图之间的空间,android,view,viewflipper,Android,View,Viewflipper,我尝试在一个ViewFlipper中制作一个包含3个视图的幻灯片动画,当我在其中切换时,会得到一个空白区域。当我试图在“移动”中更改视图时,有没有办法消除视图之间的空间,使它们看起来像是粘在一起的 以下是XML: <ViewFlipper android:id="@+id/ViewFlipper1" android:layout_height="300dp" android:layout_width="300dp" android:background="
<ViewFlipper
android:id="@+id/ViewFlipper1"
android:layout_height="300dp"
android:layout_width="300dp"
android:background="#000000">
<TextView
android:layout_width="300dp"
android:layout_height="200dp"
android:background="#aabbcc"/>
<TextView
android:layout_width="300dp"
android:layout_height="200dp"
android:background="#cfcfcf"/>
<TextView
android:layout_width="300dp"
android:layout_height="200dp"
android:background="#adadad"/>
</ViewFlipper>
下面是我正在制作的动画:
float firstTouchX = 0;
float leaveTouchX = 0;
float firstTouchX2 = 0;
float leaveTouchX2 = 0;
float oldMoveTouchX = 0;
ViewFlipper VF = null;
public boolean dispatchTouchEvent(MotionEvent event) {
VF =(ViewFlipper) findViewById(R.id.ViewFlipper1);
int eventaction=event.getAction();
final View currentView = VF.getCurrentView();
switch(eventaction) {
case MotionEvent.ACTION_DOWN:
firstTouchX = event.getX();
oldMoveTouchX = firstTouchX;
break;
case MotionEvent.ACTION_MOVE:
int deltaMovement = (int)(event.getX() - oldMoveTouchX);
oldMoveTouchX = event.getX();
if(deltaMovement < 0 )
{
currentView.layout((int)(currentView.getLeft()+deltaMovement),
currentView.getTop(), (int)(currentView.getRight()+deltaMovement),
currentView.getBottom());
}
else
{
currentView.layout((int)(currentView.getLeft()+deltaMovement),
currentView.getTop(), (int)(currentView.getRight()+deltaMovement),
currentView.getBottom());
}
break;
case MotionEvent.ACTION_UP:
leaveTouchX = event.getX();
if (firstTouchX - 50 > leaveTouchX) {
VF.setInAnimation(AnimationHelper.inFromRightAnimation());
VF.setOutAnimation(AnimationHelper.outToLeftAnimation());
VF.showNext();
}
else if (firstTouchX + 50 < leaveTouchX) {
VF.setInAnimation(AnimationHelper.inFromLeftAnimation());
VF.setOutAnimation(AnimationHelper.outToRightAnimation());
VF.showPrevious();
}
break;
}
return true;
}
public static class AnimationHelper {
public static Animation inFromRightAnimation() {
Animation inFromRight = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, +1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
inFromRight.setDuration(500);
return inFromRight;
}
public static Animation outToLeftAnimation() {
Animation outtoLeft = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, -1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
outtoLeft.setDuration(500);
return outtoLeft;
}
// for the next movement
public static Animation inFromLeftAnimation() {
Animation inFromLeft = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, -1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
inFromLeft.setDuration(500);
return inFromLeft;
}
public static Animation outToRightAnimation() {
Animation outtoRight = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, +1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
outtoRight.setDuration(500);
return outtoRight;
}
}
float firstTouchX=0;
浮点数x=0;
float firstTouchX2=0;
浮点数x2=0;
浮动oldMoveTouchX=0;
ViewFlipper VF=null;
公共布尔dispatchTouchEvent(MotionEvent){
VF=(ViewFlipper)findViewById(R.id.ViewFlipper1);
int eventaction=event.getAction();
最终视图currentView=VF.getCurrentView();
开关(事件操作){
case MotionEvent.ACTION\u DOWN:
firstTouchX=event.getX();
oldMoveTouchX=第一个TouchX;
打破
case MotionEvent.ACTION\u移动:
int deltaMovement=(int)(event.getX()-oldMoveTouchX);
oldMoveTouchX=event.getX();
如果(增量移动<0)
{
currentView.layout((int)(currentView.getLeft()+deltaMovement),
currentView.getTop(),(int)(currentView.getRight()+deltaMovement),
currentView.getBottom());
}
其他的
{
currentView.layout((int)(currentView.getLeft()+deltaMovement),
currentView.getTop(),(int)(currentView.getRight()+deltaMovement),
currentView.getBottom());
}
打破
case MotionEvent.ACTION\u UP:
levetouchx=event.getX();
如果(firstTouchX-50>leaveTouchX){
setinaimation(AnimationHelper.infomrightanimation());
setOutAnimation(AnimationHelper.outToLeftAnimation());
VF.showNext();
}
否则如果(firstTouchX+50
视图中的翻转器:-
android:layout_height=“300dp”
android:layout_width=“300dp”
取而代之的是
android:layout_height="wrap_content"
android:layout_width="wrap_content"
不是这样,我想在使用ActionMove滚动时删除它们之间的空格。如果有些人不理解,当我将view1向左移动时,我希望view2从右侧移动,并且在它们之间不留空格。