2015-05-29 31 views
0

我在Android Eclipse中使用viewFlipper。當程序調用startFlipping()時,圖像將從右向左滑動。因此,每次在stopFlipping()之後調用startFlipping()時,都會有空白背景。
我想要的是,當startFlipping()調用時,圖像將保持靜止,而不是再次從右向左滑動。Android ViewFlipper在啓動時保持圖像翻轉

這是我RES /動畫文件

<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

如果您將ViewFlipper的佈局交織在一起。交錯的ViewFlipper成linear_frame佈局,這種線性/幀佈局喊來交織成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> 
+0

我想,這是不是我要求......但不管怎麼說thx爲你的答案 – KLAng