Android面试经验Android开发经验谈Android技术知识

【Android 基础】Progressbar 实现Loadin

2017-06-27  本文已影响2164人  dongbingliu
image.png

Progressbar 实现Loading动画

网络加载,播放视频 loading 时候界面会显示 转圈 等待提示动画,使用Android 自带的Progressbar 即可实现,在使用的时候控制其Visible 属性;

布局layout目录文件中添加Progressbar

<ProgressBar
            android:id="@+id/help_center_loading_prgbar"
            style="@style/CustomProgressBar_Small"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:visibility="visible"/>

Value/style.xml中添加:

<style name="CustomProgressBar_Small">
        <item name="android:indeterminateDrawable">@drawable/progress_small_holo</item>
        <item name="android:minWidth">27dip</item>
        <item name="android:maxWidth">27dip</item>
        <item name="android:minHeight">27dip</item>
        <item name="android:maxHeight">27dip</item>
    </style>

drawable 目录添加progress_small_holo.xml 文件

<?xml version="1.0" encoding="utf-8"?>
<!--
 Copyright 2010, The Android Open Source Project

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <rotate
             android:drawable="@drawable/loading_small"
             android:pivotX="50%"
             android:pivotY="50%"
             android:fromDegrees="0"
             android:toDegrees="720" />
    </item>
</layer-list>
上一篇 下一篇

猜你喜欢

热点阅读