我在Android Eclipse中使用viewFlipper。当程序调用startFlipping()时,图像将从右向左滑入。因此,每次在stopFlipping()之后调用startFlipping()时,都会有一个空白背景 我想要的是当调用startFlipping()时,图像将保持静止而不是再次从右向左滑动。
这是我的res / anim文件
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator">
<translate
android:fromXDelta="100%p"
android:toXDelta="0"
android:duration="500"/>
</set>
这是我的xml文件
<ViewFlipper
android:id="@+id/flipper1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:flipInterval="3000"
android:inAnimation="@anim/slide_in_right"
android:outAnimation="@anim/slide_out_left">
<ImageView
android:id="@+id/main_background1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/space1"
android:adjustViewBounds="true"
android:scaleType="centerCrop"/>
<ImageView
android:id="@+id/main_background12"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/space2"
android:adjustViewBounds="true"
android:scaleType="centerCrop"/>
</ViewFlipper>
<Button
android:id="@+id/start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start"
android:onClick="startMethod"
android:layout_gravity="bottom"/>
<Button
android:id="@+id/stop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="stopMethod"
android:text="Stop"
android:layout_gravity="bottom|right"
/>
这是我的班级文件
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
flipper1 = (ViewFlipper) findViewById(R.id.flipper1);
// flipper1.startFlipping();
}
public void startMethod(View view){
flipper1.startFlipping();
}
public void stopMethod(View view){
flipper1.stopFlipping();
}
感谢您的帮助。
答案 0 :(得分:0)
如果你将ViewFlipper的布局交错。将ViewFlipper交织成一个linear_frame-layout,这个线性/帧布局的喊叫是interlace into linearr_frame布局,这是主要的布局,请按照:
<?xml version="1.0" encoding="utf-8">
<FrameLayout xmlns:android="htt....>
<View android:layout_height="1dp"
android:layout="fill_parent"
android:background="#01Ff13">
<LinearLayout-thefirst..>
<you image here />
</end from linearlayou-the first>
<Linearlayout-the second..>
<yourViewFlipper with the elements should animated../>
<end fromlinearlayout-thesecound/>
</FrameLayout>