Android实用视图动画及工具系列之一:简单的载入视图和载入动画

实现效果



功能说明

简单的载入视图和载入动画,相信大家一听名字就知道是些什么功能了,本Demo主要实现了安卓逐帧动画的开始播放,暂停和停止功能,适用于新手及新学习Android的码友们,老玩家当然也可以看看,这个还是挺简单挺实用的,在后面会简略介绍实现方法及源代码,同时博客的最后还提供源代码和图片等资源github下载地址。

实现步骤

步骤一:添加逐帧动画资源

顾名思义,逐帧动画就是一帧一帧的播放,在Android原生组件不主持gif的情况下,我们要实现逐帧动画只能使用一张一张图片来逐帧播放以达到效果,如下面的几张图(其他图片资源在源代码内,需要的自行下载,有白色和灰色两套资源):


将所有帧图片导入到Android项目目录的drawable文件夹下:



步骤二:新建逐帧动画Drawable

在drawable目录下新建xml,取名loading_progress_gray_rotate,输入如下代码(附属性说明):
animation-list:Android动画列表 
oneshot:true播放一次,false循环播放
item:每项动画
android:drawable:图片索引
android:duration:每帧持续时间
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:oneshot="false" >

    <item android:duration="100" android:drawable="@drawable/loading_gray_01">
    </item>
    <item android:duration="100" android:drawable="@drawable/loading_gray_02">
    </item>
    <item android:duration="100" android:drawable="@drawable/loading_gray_03">
    </item>
    <item android:duration="100" android:drawable="@drawable/loading_gray_04">
    </item>
    <item android:duration="100" android:drawable="@drawable/loading_gray_05">
    </item>
    <item android:duration="100" android:drawable="@drawable/loading_gray_06">
    </item>
    <item android:duration="100" android:drawable="@drawable/loading_gray_07">
    </item>
    <item android:duration="100" android:drawable="@drawable/loading_gray_08">
    </item>
    <item android:duration="100" android:drawable="@drawable/loading_gray_09">
    </item>
    <item android:duration="100" android:drawable="@drawable/loading_gray_10">
    </item>
    <item android:duration="100" android:drawable="@drawable/loading_gray_11">
    </item>
    <item android:duration="100" android:drawable="@drawable/loading_gray_12">
    </item>

</animation-list>

步骤三:新建自定义动画类

新建类ListAniImageView,代码如下,此类主要继承自ImageView,实现了基本动画播放,暂停和停止功能,注意包名改为自己的:
package com.jaiky.test.loadinganimation;

import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.util.AttributeSet;
import android.widget.ImageView;

/**
 * Author by Jaiky, Email jaikydota@163.com, Date on 9/22/2016.
 * PS: Not easy to write code, please indicate.
 */
public class ListAniImageView extends ImageView {

    private AnimationDrawable animationDrawable;

    public ListAniImageView(Context context) {
        super(context);
        inti();

    }

    public ListAniImageView(Context context, AttributeSet attrs) {
        super(context, attrs);
        inti();
    }

    public ListAniImageView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        inti();
    }

    public void inti() {
        animationDrawable = (AnimationDrawable) getDrawable();
        animationDrawable.start();
    }

    public void startAnimation() {
        animationDrawable.start();
    }

    public void stopAnimation() {
        animationDrawable.setVisible(true, true);
        animationDrawable.stop();
    }

    public void pauseAnimation() {
        animationDrawable.stop();
    }

}

步骤四:Demo测试修改布局和主类

修改activity_main.xml内容如下(注意自定义控件包名):
<?xml version="1.0" encoding="utf-8"?>
<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:background="@android:color/black"
    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.jaiky.test.loadinganimation.MainActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <Button
            android:id="@+id/btn1"
            android:text="暂停"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1" />

        <Button
            android:id="@+id/btn2"
            android:text="停止"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1" />

        <Button
            android:id="@+id/btn3"
            android:text="开始"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1" />
    </LinearLayout>

    <com.jaiky.test.loadinganimation.ListAniImageView
        android:id="@+id/flGray"
        android:layout_width="35dp"
        android:layout_height="35dp"
        android:layout_centerInParent="true"
        android:src="@drawable/loading_progress_gray_rotate" />

    <com.jaiky.test.loadinganimation.ListAniImageView
            android:id="@+id/flWhite"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_centerVertical="true"
        android:src="@drawable/loading_progress_white_rotate" />
</RelativeLayout>

修改MainActiivty内容如下(注意包名):
package com.jaiky.test.loadinganimation;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    Button btn1, btn2, btn3;
    ListAniImageView flWhite, flGray;

    Object mObject;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btn1 = (Button) findViewById(R.id.btn1);
        btn2 = (Button) findViewById(R.id.btn2);
        btn3 = (Button) findViewById(R.id.btn3);
        flWhite = (ListAniImageView) findViewById(R.id.flWhite);
        flGray = (ListAniImageView) findViewById(R.id.flGray);

        //暂停动画(停留在当前帧)
        btn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                flWhite.pauseAnimation();
                flGray.pauseAnimation();
            }
        });
        //停止动画(停止到第一帧)
        btn2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                flWhite.stopAnimation();
                flGray.stopAnimation();
            }
        });
        //开始动画
        btn3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                flWhite.startAnimation();
                flGray.startAnimation();
            }
        });
    }
}

--------------------------------------------------------------------------------------------------------------------
获取源代码及资源文件:
--------------------------------------------------------------------------------------------------------------------

声明

欢迎转载,但请保留文章原始出处
作者:Jaiky_杰哥 
出处:http://blog.csdn.net/jaikydota163/article/details/52098833



  • 10
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
### 回答1: 在 ArcMap 的 Layout 视图下,可以通过以下步骤来调整图形的线宽度: 1. 选择要调整线宽度的图形 2. 在布局面板中找到“属性”选项 3. 在“属性”选项中找到“线宽度”并调整为所需大小 4. 应用更改。 ### 回答2: 在ArcMap的Layout视图下,要调整图形线的宽度可以通过以下步骤进行操作: 1. 打开ArcMap软件,载入要进行操作的地图文档。 2. 切换到Layout视图,在导航栏上找到“Insert”选项,点击打开下拉菜单。 3. 在下拉菜单中选择“Graphic Options”,然后再选择“Line Width”选项。 4. 在弹出的对话框中,可以看到当前图形线的宽度,默认为1个像素。可以通过拖动滑块或手动输入数值的方式进行修改。 5. 若需要将线的宽度调小,可以拖动滑块或输入较小的数值,然后点击“OK”按钮确认修改。 6. 此,图形线的宽度就会按照所设定的值进行调整,并在Layout视图中显示。 需要注意的是,在修改图形线的宽度需要根据具体情况来确定合适的数值。若线的宽度过小,可能会导致在地图输出线条不清晰或不可见,因此需要根据具体需求来进行调整。而且,此操作只会影响Layout视图中的显示效果,对实际地图数据并无影响。 以上就是在ArcMap的Layout视图下,将图形线宽度调小的简要步骤说明。希望能帮助到您! ### 回答3: 在ArcMap的layout视图下,要将图形线宽度调小,可以按照以下步骤进行操作。 1. 打开ArcMap软件并加载需要调整线宽的地图。 2. 切换到layout视图,这可以通过单击软件窗口右下方的layout视图按钮来实现。 3. 在layout视图中,选择需要调整线宽的图形元素,可以是点、线或面要素。 4. 单击鼠标右键,在弹出的菜单中选择"Properties"(属性)选项。 5. 在"Symbol Selector"(符号选择器)对话框中,可以根据需要选择不同的符号样式,例如线的颜色、类型、端点样式等。 6. 在"Symbol Property Editor"(符号属性编辑器)对话框中,点击左侧的"Line Properties"(线属性)选项卡。 7. 在"Line Properties"选项卡中,找到"Width"(宽度)选项,通过滑动滑块或手动输入数值来调整线的宽度。需要注意的是,较小的数值将会得到细线,较大的数值将得到粗线。 8. 调整完成后,点击"OK"按钮保存更改,并关闭相关对话框。 9. 可以通过缩放布局视图或切换到数据视图来查看调整后的线宽效果。 通过以上步骤,您可以在ArcMap的layout视图中将图形线宽度调小,以适应您的具体需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值