Android 中上拉加载更多控件效果的实现

简介: Android 中上拉加载更多控件效果的实现

一、先上效果图

需要的就往下看,详细代码加步骤

1、创建xml,注释都已经在代码中写出。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:orientation="vertical"
    >
    <!--分割线-->
    <View
        style="@style/horizontalDivider"
        />
    <!-- indeterminateDrawable效果为自定义图片让其不断的旋转-->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:gravity="center"
        >
        <ProgressBar
            android:id="@+id/footer_progress"
            android:layout_width="20dp"
            android:layout_height="20dp"
            android:layout_marginRight="8dp"
            android:indeterminateDrawable="@drawable/update_loading_progressbar"
            android:visibility="visible"
            />
        <TextView
            android:id="@+id/footer_tv_load"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="加载更多"
            android:textColor="#999999"
            android:textSize="14dp"
             />
    </LinearLayout>
</LinearLayout>

2、资源文件horizontalDivider如下:

<resources>
 <!-- 水平分割线 -->
    <style name="horizontalDivider">
        <item name="android:layout_width">match_parent</item>
        <item name="android:layout_height">1dp</item>
        <item name="android:background">@color/grey</item>
    </style>
 </resources>

2.1、资源文件update_loading_progressbar如下:

<?xml version="1.0" encoding="utf-8"?>
<!--rotate 旋转动画-->
<!--fromDegrees初始角度-->
<!--toDegrees 结束时角度,值为正值时,顺时针旋转.
值为负值时,逆时针旋转-->
<!--pivotX 旋转中心坐标,取值可以是数值(50)
    百分数(50%) 百分数p(50%p)
    当取值为数值时:缩放起点为View左上角坐标加上具体数值像素。
    当取值为百分数时:表示在当前View的左上角坐标加上View宽度的具体百分比
    当取值为百分数P时,表示在View左上角坐标加上父控件宽度的百分比
-->
<!--pivotY 同上-->
<!--duration 动画持续时间,毫秒为单位-->
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@mipmap/default_ptr_rotate_gray"
    android:duration="700"
    android:fromDegrees="0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toDegrees="720"
    >
</rotate>

代码和资源文件都已经写出,实现上拉加载更多时,可以用到该控件,在此记录一下,方便以后用到,直接用即可!


目录
相关文章
|
6天前
|
XML Java Android开发
Android控件动态使用 (转)
Android控件动态使用 (转)
10 1
|
6天前
|
编解码 调度 Android开发
Android音频框架之一 详解audioPolicy流程及HAL驱动加载与配置
Android音频框架之一 详解audioPolicy流程及HAL驱动加载与配置
22 0
|
6天前
|
Android开发
Android中Glide加载Https图片失败的解决方案
Android中Glide加载Https图片失败的解决方案
19 1
|
6天前
|
Android开发
Android Mediatek NVRAM 加载 MAC 地址并禁用 MAC 地址更新
Android Mediatek NVRAM 加载 MAC 地址并禁用 MAC 地址更新
8 0
|
6天前
|
XML Java Android开发
Android控件之基础控件——进度条类的view——TextView、Checkbox复选控件、RadioButton单选控件、ToggleButton开关、SeekBar拖动条、menu、弹窗
Android控件之基础控件——进度条类的view——TextView、Checkbox复选控件、RadioButton单选控件、ToggleButton开关、SeekBar拖动条、menu、弹窗
|
6天前
|
XML 编解码 Java
Android控件之高级控件——ListView、cardView、屏幕适配
Android控件之高级控件——ListView、cardView、屏幕适配
|
6天前
|
Android开发
Android控件——Checkbox复选框、RadioButton单选、ToggleButton开关、SeekBar拖动条
Android控件——Checkbox复选框、RadioButton单选、ToggleButton开关、SeekBar拖动条
|
6天前
|
XML Java Android开发
Android之UI基础控件
Android之UI基础控件
|
6天前
|
Android开发
[Android]RadioButton控件
[Android]RadioButton控件
14 0
|
6天前
|
Android开发
分享88个Android控件源代码总有一个是你想要的
分享88个Android控件源代码总有一个是你想要的
27 0