MainActivity.java

public class MainActivity extends AppCompatActivity {
private ImageView iv;
private int j = 0;
private Button enter;
private LinearLayout leftLayout, rightLayout; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); // iv = (ImageView) findViewById(R.id.iv); change(); leftLayout = (LinearLayout) findViewById(R.id.layout_left);
rightLayout = (LinearLayout) findViewById(R.id.layout_right); TopBar topBar = (TopBar) findViewById(R.id.topbar);
topBar.setOnTopBarClickListener(new TopBar.TopBarClickListener() {
@Override
public void onLeftClick() {
Toast.makeText(MainActivity.this, "left", Toast.LENGTH_SHORT).show(); /*LayoutInflater inflater = LayoutInflater.from(MainActivity.this);
View view = inflater.inflate(R.layout.item, null);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
addContentView(view,params);*/ // twoAnimation(); // offSet(); // flash(); Animation animation = AnimationUtils.loadAnimation(MainActivity.this,R.anim.all);
leftLayout.startAnimation(animation); leftLayout.setVisibility(View.VISIBLE);
rightLayout.setVisibility(View.GONE);
} @Override
public void onRightClick() {
Toast.makeText(MainActivity.this, "right", Toast.LENGTH_SHORT).show(); rightLayout.setVisibility(View.VISIBLE);
leftLayout.setVisibility(View.GONE);
}
});
} //Activity交换时的动画效果
public void change() {
enter = (Button) findViewById(R.id.btn_enter);
enter.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "haha", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(MainActivity.this, EnterActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.activity_enter, R.anim.activity_out);
}
});
} //闪动效果
public void flash() {
Animation animation = AnimationUtils.loadAnimation(MainActivity.this,R.anim.flash);
leftLayout.startAnimation(animation);
} //给某些动画设置了延迟时间
public void offSet() {
Animation animation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.offset);
leftLayout.startAnimation(animation);
} //一个动画接着一个动画
public void twoAnimation() {
Animation animation1 = new AlphaAnimation(0.1f, 1.0f);
final Animation animation2 = new ScaleAnimation(0.1f, 1.0f, 0.1f, 1.0f);
animation1.setDuration(2000);
animation2.setDuration(2000);
leftLayout.startAnimation(animation1);
animation1.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) { } @Override
public void onAnimationEnd(Animation animation) {
leftLayout.startAnimation(animation2);
} @Override
public void onAnimationRepeat(Animation animation) { }
});
} }

EnterActivity.java

public class EnterActivity extends AppCompatActivity {
private ImageView iv; private Button btn; private List<String> mData;
private ListView listview; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_enter); iv = (ImageView) findViewById(R.id.iv);
btn = (Button) findViewById(R.id.btn_myworld); listview = (ListView) findViewById(R.id.listview);
mData = new ArrayList<String>(); for (int i = 0; i < 10; i++) {
mData.add("" + i);
} ArrayAdapter<String> mAdapter = new ArrayAdapter<String>(
EnterActivity.this, android.R.layout.simple_list_item_1, mData);
listview.setAdapter(mAdapter); LayoutAnimationController lac = new LayoutAnimationController(
AnimationUtils.loadAnimation(this, R.anim.flash));
lac.setOrder(LayoutAnimationController.ORDER_RANDOM);
listview.setLayoutAnimation(lac);
listview.startLayoutAnimation(); btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
listview.setVisibility(View.GONE); iv.setVisibility(View.VISIBLE);
iv.setImageResource(R.drawable.image_list);
AnimationDrawable drawable = (AnimationDrawable) iv.getDrawable();
drawable.start();
}
});
}
}

TopBar.java

public class TopBar extends RelativeLayout {
private Button leftBtn, rightBtn;
private TextView title; private int leftTextColor;
private Drawable leftBackground;
private String leftText; private int rightTextColor;
private Drawable rightBackground;
private String rightText; private int titleColor;
private float titleTextSize;
private String titleText; private LayoutParams leftParams, rightParams, titleParams; public interface TopBarClickListener {
void onLeftClick();
void onRightClick();
} private TopBarClickListener listener; public void setOnTopBarClickListener (TopBarClickListener listener) {
this.listener = listener;
} public TopBar(Context context, AttributeSet attrs) {
super(context, attrs); //1.
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.topBar); leftTextColor = ta.getColor(R.styleable.topBar_leftTextColor, 0);
leftBackground = ta.getDrawable(R.styleable.topBar_leftBackground);
leftText = ta.getString(R.styleable.topBar_leftText); rightTextColor = ta.getColor(R.styleable.topBar_rightTextColor, 0);
rightBackground = ta.getDrawable(R.styleable.topBar_rightBackground);
rightText = ta.getString(R.styleable.topBar_rightText); titleColor = ta.getColor(R.styleable.topBar_titleTextColors, 0);
titleTextSize = ta.getDimension(R.styleable.topBar_titleTextSize, 0);
titleText = ta.getString(R.styleable.topBar_titleText); //回收资源,避免浪费,避免缓存造成的影响
ta.recycle(); //2.
leftBtn = new Button(context);
rightBtn = new Button(context);
title = new TextView(context); leftBtn.setTextColor(leftTextColor);
leftBtn.setBackground(leftBackground);
leftBtn.setText(leftText);
leftBtn.setGravity(Gravity.CENTER); rightBtn.setTextColor(rightTextColor);
rightBtn.setBackground(rightBackground);
rightBtn.setText(rightText); title.setTextColor(titleColor);
title.setTextSize(titleTextSize);
title.setText(titleText);
title.setGravity(Gravity.CENTER); setBackgroundColor(0xFFF12456); //3.
leftParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
leftParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, TRUE);
addView(leftBtn, leftParams); rightParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
rightParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, TRUE);
addView(rightBtn, rightParams); titleParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT);
titleParams.addRule(RelativeLayout.CENTER_IN_PARENT, TRUE);
addView(title, titleParams); //4.
leftBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
listener.onLeftClick();
}
}); rightBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
listener.onRightClick();
}
}); }
}

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="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"> <my.com.example.x550v.uidisigndmo.TopBar
android:id="@+id/topbar"
android:layout_width="match_parent"
android:layout_height="40dp" custom:titleText="我的世界"
custom:titleTextSize="10sp"
custom:titleTextColors="#fff" custom:leftBackground="@drawable/button"
custom:leftText="上一页"
custom:leftTextColor="#000" custom:rightBackground="@drawable/button"
custom:rightText="下一页"
custom:rightTextColor="#000"/> <Button
android:id="@+id/btn_enter"
android:text="Enter"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content" /> <!--<ImageView
android:id="@+id/iv"
android:background="#f7b2b2"
android:layout_below="@id/topbar"
android:layout_width="match_parent"
android:layout_height="match_parent" />-->
<LinearLayout
android:id="@+id/layout_left"
android:orientation="vertical"
android:layout_below="@id/topbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone">
<Button
android:text="白日依山尽"
android:textSize="20sp"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ImageView
android:layout_gravity="center_horizontal"
android:background="@drawable/ahri1"
android:layout_width="200dp"
android:layout_height="380dp" />
<Button
android:text="黄河入海流"
android:textSize="20sp"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout> <LinearLayout
android:id="@+id/layout_right"
android:orientation="vertical"
android:layout_below="@id/topbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone">
<Button
android:text="欲穷千里目"
android:textSize="20sp"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ImageView
android:layout_gravity="center_horizontal"
android:background="@drawable/ahri2"
android:layout_width="200dp"
android:layout_height="380dp" />
<Button
android:text="更上一层楼"
android:textSize="20sp"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout> </RelativeLayout>

activity_enter.xml

<LinearLayout 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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context="my.com.example.x550v.uidisigndmo.EnterActivity">
<Button
android:id="@+id/btn_myworld"
android:text="我的世界观"
android:textSize="20sp"
android:layout_width="match_parent"
android:layout_height="wrap_content" /> <ListView
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="match_parent"/> <ImageView
android:id="@+id/iv"
android:layout_gravity="center_horizontal"
android:visibility="gone"
android:layout_width="250dp"
android:layout_height="500dp" /> </LinearLayout>

attrs.xml

<resources>
<declare-styleable name="topBar">
<attr name="titleText" format="string"/>
<attr name="titleTextSize" format="dimension" />
<attr name="titleTextColors" format="color"/> <attr name="leftBackground" format="reference|color"/>
<attr name="leftText" format="string"/>
<attr name="leftTextColor" format="color"/> <attr name="rightBackground" format="reference|color"/>
<attr name="rightText" format="string"/>
<attr name="rightTextColor" format="color"/> </declare-styleable>
</resources>

image_list.xml

<animation-list
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@drawable/ahri1"
android:duration="2000"/>
<item
android:drawable="@drawable/ashe"
android:duration="2000"/>
<item
android:drawable="@drawable/ahri2"
android:duration="2000"/>
<item
android:drawable="@drawable/brand"
android:duration="2000"/>
</animation-list>

all.xml

<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillBefore="false"
android:fillAfter="true">
<!--<alpha-->
<!--android:duration="2000"-->
<!--android:fromAlpha="0.1"-->
<!--android:toAlpha="1.0"/>--> <!--<scale-->
<!--android:duration="2000"-->
<!--android:fillAfter="false"-->
<!--android:fromXScale="0.1"-->
<!--android:fromYScale="0.1"-->
<!--android:toXScale="1.0"-->
<!--android:toYScale="1.0"-->
<!--android:pivotX="80%"-->
<!--android:pivotY="80%"-->
<!--android:interpolator="@android:anim/accelerate_interpolator"/>--> <translate
android:duration="2000"
android:fromXDelta="-400"
android:fromYDelta="-400"
android:toXDelta="400"
android:toYDelta="400" /> <!--<rotate-->
<!--android:duration="2000"-->
<!--android:fromDegrees="0"-->
<!--android:toDegrees="360"-->
<!--android:pivotX="30%"-->
<!--android:pivotY="30%"/>-->
</set>

Android实现控件动画效果的更多相关文章

  1. android中设置Animation 动画效果

    在 Android 中, Animation 动画效果的实现可以通过两种方式进行实现,一种是 tweened animation 渐变动画,另一种是 frame by frame animation ...

  2. Android 基本控件相关知识整理

    Android应用开发的一项重要内容就是界面开发.对于用户来说,不管APP包含的逻辑多么复杂,功能多么强大,如果没有提供友好的图形交互界面,将很难吸引最终用户.作为一个程序员如何才能开发出友好的图形界 ...

  3. Github上star数超1000的Android列表控件

    Android开发中,列表估计是最最常使用到的控件之一了.列表相关的交互如下拉刷新,上拉更多,滑动菜单,拖动排序,滑动菜单,sticky header分组,FAB等等都是十分常见的体验.Github中 ...

  4. android 地址控件概述

    最近,公司做项目,需要一个地址控件,本来是想androidcopy开源的android的地址控件,但是了,找来找去.都没有找到一个真正满足我的需求的,普通的地址控件只是精确到市县区三级,但是我们的需求 ...

  5. Android 开源控件与常用开发框架开发工具类

    Android的加载动画AVLoadingIndicatorView 项目地址: https://github.com/81813780/AVLoadingIndicatorView 首先,在 bui ...

  6. Windows Store App 控件动画

    在开发Windows应用商店应用时,开发工具中已经封装了大量的控件供开发人员使用,而其中有一部分控件,例如FlipView.ToolTip.ListView以及SemanticZoom等控件中已经默认 ...

  7. android 基础控件(EditView、SeekBar等)的属性及使用方法

        android提供了大量的UI控件,本文将介绍TextView.ImageView.Button.EditView.ProgressBar.SeekBar.ScrollView.WebView ...

  8. 矩阵, 矩阵 , Android基础控件之ImageView

    天下文章大家抄,以下所有内容,有来自copy,有来自查询,亦有自己的总结(目的是总结出自己的东西),所以说原创,不合适,说是转载也不恰当,所以我称之为笔记,可惜没有此分类选项,姑且不要脸一点,选择为原 ...

  9. Android AutoCompleteTextView控件实现类似百度搜索提示,限制输入数字长度

    Android AutoCompleteTextView 控件实现类似被搜索提示,效果如下 1.首先贴出布局代码 activity_main.xml: <?xml version="1 ...

随机推荐

  1. [5]Telerik Extensions for ASP.NET MVC 开发问题

    1.Controller获取不到checkedNodes的问题 HTML @(Html.Telerik().TreeView()        .Name("TreeView")  ...

  2. 类图和对象图教程-类(Class)、接口(Interface)、协作(collaboration)、依赖关系(Dependency)、泛化关系(Generalization)、关联关系(Association)以及实现关系(Realization)

    类图的概念 (转) 一.概述 类图(Class Diagram)是描述类.接口.协作以及它们之间关系的图,用来显示系统中各个类的静态结构.类图是定义其他图的基础,在类图基础上,可以使用状态图.协作图. ...

  3. C# 调用C++/MFC写的dll

    C#调用C++的非托管类的dll其实很简单基本就是固定的调用格式. dll的编写,首先是打开VS新建一个C++的控制台程序,下一步后选择dll以及空文档即可.然后就是添加一个类添加一个方法.方法排头固 ...

  4. MySQL基础 - 外键和约束

    在工作中经常会遇到不少不同的观点,比如对于数据库来说那就是是否要设置外键,设置外键的理由自然不必多说,而不设置外键的理由多半为设置外键影响性能,但就目前工作来讲,还没有涉及到因为外键而引发的数据库瓶颈 ...

  5. g++编译总结

    g++编译&&gdb调试&&coredump调试 一.编译注意细节 1.使用g++编译CPP文件如果用gcc编译C++源文件时,加以下选项:-lstdc++,否则使用了 ...

  6. java系列: 在eclipse中调试时,输入的jsp或者servlet页面的地址要区分大小写

    比如在当前web工程中有一个jsp页面的名字是: Welcome.jsp 在eclipse中调试时,如果在浏览器中输入: http://localhost:8080/MavenWeb/welcome. ...

  7. 实验二实验报告 20135324&&20135330

    北京电子科技学院(BESTI) 实 验 报 告 课程: 深入理解计算机系统 班级: 1353 姓名: 杨舒雯 张若嘉 学号: 20135324 20135330 成绩: 指导教师: 娄嘉鹏 实验日期: ...

  8. Jenkins进阶系列之——16一个完整的JENKINS下的ANT BUILD.XML文件

    网上看见的,确实很全,该有的基本都覆盖到了.自己拿来稍微改改就可以用了. 注:property中的value是你自己的一些本地变量.需要改成自己的 <?xml version="1.0 ...

  9. <实训|第二天>掌握linux6.7中安装vmware、vmware安装linux发行版本以及遇到的问题最后libreoffice的安装

    期待已久的linux运维.oracle"培训班"终于开班了,我从已经开始长期四个半月的linux运维.oracle培训,每天白天我会好好学习,晚上回来我会努力更新教程,包括今天学到 ...

  10. javascript中的闭包,超简单论述,保证小学生必懂

    js中的闭包已经有很多论断了,大家伙有没有听懂了,先引用一片比较高端 的 ”汤姆大叔“  深入理解JavaScript系列(16):闭包(Closures) 好了,为了引起大家的兴趣,先来小诗一首 v ...