当前位置:网站首页>Functions and usage of viewflipper

Functions and usage of viewflipper

2022-07-07 17:36:00 XLMN

viewflipper The function and usage of
viewflipper Inherited viewanimator, Callable addview(view v) Add multiple components once to viewflipper After adding multiple components ,viewflipper You can use animation to control the switching effect between multiple components
public class MainActivity extends Activity {
private ViewFlipper vf;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
            setContentView(R.layout.viewflipper);
            vf = (ViewFlipper) findViewById(R.layout.viewflipper);

    }

    public void prev(View view) {
            // TODO Auto-generated method stub
            vf.setInAnimation(this, android.R.anim.slide_in_left);
            vf.setOutAnimation(this, android.R.anim.slide_out_right);
            //  Show previous component 
            vf.showPrevious();
            //  Stop autoplay 
            vf.stopFlipping();
    }

    public void next(View view) {
            // TODO Auto-generated method stub
            vf.setInAnimation(this, android.R.anim.slide_in_left);
            vf.setOutAnimation(this, android.R.anim.slide_out_right);
            //  Show the next 
            vf.showNext();
            //  Stop autoplay 
            vf.stopFlipping();
    }

    public void auto(View view) {
            // TODO Auto-generated method stub
            vf.setInAnimation(this, android.R.anim.slide_in_left);
            vf.setOutAnimation(this,android.R.anim.slide_out_right);
            //  Start autoplay 
            vf.startFlipping();
    }

}

<?xml version="1.0" encoding="utf-8"?>

<!-- android:flipInterval="1000" It means setting up every one of them View Time shown ; -->

<ViewFlipper
    android:id="@+id/viewflipper"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:flipInterval="1000" >

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/love" />

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/mia" />

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/mia10" />
</ViewFlipper>

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:onClick="prev"
    android:text="&amp;lt" />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerInParent="true"
    android:onClick="auto"
    android:text=" Auto play " />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:onClick="next"
    android:text="&amp;gt" />

 Insert picture description here

原网站

版权声明
本文为[XLMN]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207071527553959.html