ViewFlipper的使用

ViewFlipper,好像一个容器!!!,你可以把许多的View放在这个容器中,让它展示给用户,虽然它每次只展示一个,话不多说直接上原码!

1、创建布局文件并且在布局里加上ViewFlipper==ImageView

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
  >
 <ViewFlipper
     android:id="@+id/vf"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent">
<LinearLayout 
      android:id="@+id/lauout1"<pre name="code" class="html"><?xml version="1.0" encoding="utf-8"?>
<translate  xmlns:android="http://schemas.android.com/apk/res/android"
    	android:duration="1000"
    	android:fromXDelta="0"
    	android:toXDelta="100%p"
    	/>

    

android:layout_width="fill_parent" android:layout_height="fill_parent" > <ImageView android:id="@+id/image1" android:src="@drawable/abc" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout><LinearLayout android:id="@+id/lauout2" android:layout_width="fill_parent" android:layout_height="fill_parent" > <ImageView android:id="@+id/image2" android:src="@drawable/championsskin_15003" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout><LinearLayout android:id="@+id/lauout3" android:layout_width="fill_parent" android:layout_height="fill_parent" > <ImageView android:id="@+id/image3" android:src="@drawable/championsskin_15004" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout></ViewFlipper>
</LinearLayout>
 2、创建anim的xml文件好四个特效 

in_leftright.xml文件、in_rightleft.xml文件、out_leftright.xml文件、out_rightleft.xml文件。例如in_leftright.xml

<?xml version="1.0" encoding="utf-8"?>
<translate  xmlns:android="http://schemas.android.com/apk/res/android"
    	android:duration="1000"
    	android:fromXDelta="0"
    	android:toXDelta="100%p"
    	/>
1000表示一秒,0表示进来的横坐标,100表示出去的横坐标
3、代码部分创建ViewFlipper

public class MainActivity extends Activity implements OnTouchListener {
	private ViewFlipper vf;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        vf=(ViewFlipper) findViewById(R.id.vf);
        vf.setOnTouchListener(this);
    }

4、实现触屏事件并添加图片例如

public class MainActivity extends Activity implements OnTouchListener {
	private ViewFlipper vf;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        vf=(ViewFlipper) findViewById(R.id.vf);
        vf.setOnTouchListener(this);
    }





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值