Android 循环滚动控件ViewFlipper,可实现跑马灯或轮播图效果

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

    android:fromYDelta="0"

    android:toYDelta="-100%p"

    android:duration="1000"/>



左右滚动动画



x\_in.xml



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

    android:fromXDelta="100%p"

    android:toXDelta="0"

    android:duration="1000"/>



x\_out.xml



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

    android:fromXDelta="0"

    android:toXDelta="-100%p"

    android:duration="1000"/>



### (2)layout文件引用ViewFlipper



<ViewFlipper

android:id="@+id/filpper"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:autoStart="true"

android:flipInterval="2000"

android:inAnimation="@anim/x_in"

android:outAnimation="@anim/x_out"/>



### (3)activity中java代码实现ViewFlipper跑马灯效果



TextView textView;

ViewFlipper viewFlipper;


viewFlipper= (ViewFlipper) findViewById(R.id.filpper);

for (int i = 0; i < 5; i++) {

View view = LayoutInflater.from(getApplicationContext()).inflate(R.layout.layout_custom, null);

textView = view.findViewById(R.id.myte1);

textView.setText("sssssssss===="+i);



viewFlipper.addView(view);

}




4、ViewFlipper的item点击事件——demo链接:[https://download.youkuaiyun.com/download/meixi\_android/10815720]( )



5、demo云盘链接:[https://pan.baidu.com/s/1AvqpfbzCAXtZ-TLVmEUyvw]( )



在线回复云盘密码:qq1085220040



6、可实现banner轮播图效果

================



### 左右跑马灯



<LinearLayout

android:id="@+id/ll\_bottom"

android:layout\_width="match\_parent"

android:layout\_height="wrap\_content"

android:layout\_alignParentBottom="true"

android:background="#FDC74B">

<TextView

android:id="@+id/tv\_message"

android:layout\_width="match\_parent"

android:layout\_height="wrap\_content"

android:layout\_marginLeft="15pt"

android:layout\_marginRight="15pt"

android:ellipsize="marquee"

android:focusable="true"

android:focusableInTouchMode="true"

android:gravity="center\_vertical"

android:includeFontPadding="false"

android:marqueeRepeatLimit="marquee\_forever"

android:paddingBottom="15pt"

android:paddingTop="15pt"

android:singleLine="true"

android:textColor="@color/black"

android:textSize="36pt" />



public class StringUtil {

//长度加倍

public static String multiplyString(String str, int number) {

    if (str == null) {

        throw new NullPointerException("String is null!");

    }

    if ("".equals(str)) {

        throw new IllegalArgumentException("The length of string is zero !");

    }

    if (number == 0) {

        throw new IllegalArgumentException("Number is zero!");

    }

    StringBuffer buffer = new StringBuffer();

    for (int i = 0; i < number; i++) {

        buffer.append(str);

    }

    return buffer.toString();

}

}


tvMessage.setText(aboutUsResult.getData().getApkmsg() + StringUtil.multiplyString(" ", 30));

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值