Android实现控件动画效果
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实现控件动画效果的更多相关文章
- android中设置Animation 动画效果
在 Android 中, Animation 动画效果的实现可以通过两种方式进行实现,一种是 tweened animation 渐变动画,另一种是 frame by frame animation ...
- Android 基本控件相关知识整理
Android应用开发的一项重要内容就是界面开发.对于用户来说,不管APP包含的逻辑多么复杂,功能多么强大,如果没有提供友好的图形交互界面,将很难吸引最终用户.作为一个程序员如何才能开发出友好的图形界 ...
- Github上star数超1000的Android列表控件
Android开发中,列表估计是最最常使用到的控件之一了.列表相关的交互如下拉刷新,上拉更多,滑动菜单,拖动排序,滑动菜单,sticky header分组,FAB等等都是十分常见的体验.Github中 ...
- android 地址控件概述
最近,公司做项目,需要一个地址控件,本来是想androidcopy开源的android的地址控件,但是了,找来找去.都没有找到一个真正满足我的需求的,普通的地址控件只是精确到市县区三级,但是我们的需求 ...
- Android 开源控件与常用开发框架开发工具类
Android的加载动画AVLoadingIndicatorView 项目地址: https://github.com/81813780/AVLoadingIndicatorView 首先,在 bui ...
- Windows Store App 控件动画
在开发Windows应用商店应用时,开发工具中已经封装了大量的控件供开发人员使用,而其中有一部分控件,例如FlipView.ToolTip.ListView以及SemanticZoom等控件中已经默认 ...
- android 基础控件(EditView、SeekBar等)的属性及使用方法
android提供了大量的UI控件,本文将介绍TextView.ImageView.Button.EditView.ProgressBar.SeekBar.ScrollView.WebView ...
- 矩阵, 矩阵 , Android基础控件之ImageView
天下文章大家抄,以下所有内容,有来自copy,有来自查询,亦有自己的总结(目的是总结出自己的东西),所以说原创,不合适,说是转载也不恰当,所以我称之为笔记,可惜没有此分类选项,姑且不要脸一点,选择为原 ...
- Android AutoCompleteTextView控件实现类似百度搜索提示,限制输入数字长度
Android AutoCompleteTextView 控件实现类似被搜索提示,效果如下 1.首先贴出布局代码 activity_main.xml: <?xml version="1 ...
随机推荐
- Gradle的HelloWorld
Gradle的脚本名为 build.gradle task hello{ doLast{ println("Hello World") } } 运行:gradle -q hell ...
- [5]Telerik Extensions for ASP.NET MVC 开发问题
1.Controller获取不到checkedNodes的问题 HTML @(Html.Telerik().TreeView() .Name("TreeView") ...
- yum标准化安装nginx最新版
yum标准化安装nginx最新版 cat > /etc/yum.repos.d/nginx.repo [nginx] name=nginx repo baseurl=http://nginx.o ...
- 数据挖掘系列(4)使用weka做关联规则挖掘
前面几篇介绍了关联规则的一些基本概念和两个基本算法,但实际在商业应用中,写算法反而比较少,理解数据,把握数据,利用工具才是重要的,前面的基础篇是对算法的理解,这篇将介绍开源利用数据挖掘工具weka进行 ...
- 如何构建JSON数据,JSON数据的格式,JSON数据的获取
假设你是用$.getJSON();方法获取JSON数据$.getJSON(url,{"Action":"getStudent"},function(data){ ...
- HTTP之手机抓包工具篇
简介 现在手机移动互联网时代 手机app 运用 如日冲天.自然手机app的问题排除也是头疼,明明自己测试 上线的接口正常 到了手机app就不行.怎么办呢?别急,现在有好多手机抓包工具啦! 1. Cha ...
- DateTime.Parse
上月第一天:DateTime.Parse(DateTime.Now.AddMonths(-1).ToString("yyyy-MM-01")) 上周星期天:DateTime.Par ...
- [wikioi 1519]过路费(最小生成树+树链剖分)
题目:http://www.wikioi.com/problem/1519/ 题意:给你一个连通的无向图,每条边都有权值,给你若干个询问(x,y),要输出从x到y的路径上边的最大值的最小值 分析:首先 ...
- 第三十三课:jQuery Deferred详解1
之前我们讲了Mochikit Deferred,JSDeferred,现在讲jQuery Deferred.首先,我们先来讲下他们的区别: 在保存回调函数时,Mochikit Deferred(doj ...
- linux 安装webbench
webbench :1.5 http://soft.vpser.net/test/webbench/webbench-1.5.tar.gz从官网下载webbench-1.5.tar.gz1.解压 t ...