现在的位置: 首页 > 综合 > 正文

不确定水平滚动条的循环滚动的实现。

2018年04月04日 ⁄ 综合 ⁄ 共 1694字 ⁄ 字号 评论关闭

1、在activity_main.xml中定义进度条。

<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.mktech.progressbar.MainActivity" >

    <ProgressBar
        android:id="@+id/progressbar"
        android:layout_height="34dp"
        android:layout_width="400dp"
        android:indeterminate="true"
        android:indeterminateOnly="true"  //说明进度条是不确定的
        style="@style/progressbar"/>       
</RelativeLayout>

2、在value下创建style.xml,用来定义进度条的风格。

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
    <style name = "progressbar" parent="android:Widget.ProgressBar.Horizontal">
        <item name = "android:indeterminateDrawable">@drawable/progressbar_horizontal</item>
        <item name = "android:minHeight">10dp</item>
        <item name = "android:maxHeight">40dp</item>
    </style>
</resources>

3、在drawable下创建progressbar_horizontal,定义实现进度条的图片等。

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false">
    <item android:drawable = "@drawable/progressbar_01" android:duration = "100"/>
    <item android:drawable = "@drawable/progressbar_02" android:duration = "100"/>
    <item android:drawable = "@drawable/progressbar_03" android:duration = "100"/>
</animation-list>

其中,oneshot为true,表示动画只播放一次停止在最后一帧上,如果设置为false表示动画循环播放。
注意:实现进度条的循环滚动的图片必须相互之间能够实现滚动效果。

抱歉!评论已关闭.