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. 02SpringMvc_springmvc快速入门小案例(XML版本)

    这篇文章中,我们要写一个入门案例,去整体了解整个SpringMVC. 先给出整个项目的结构图:

  2. 【转】【C#】【Thread】Interlocked 轻量级锁

    为什么说它是轻量级呢?因为它仅对整形数据(即int类型,long也行)进行同步. 具体使用如下表: Interlocked.Increment(ref value) 数值加一(原子性操作) Inter ...

  3. 如何免费访问Google?

    访问Google方法(以Mac为例) 1.替换hosts文件中的内容,文件链接如下: https://github.com/racaljk/hosts 2.下载Google浏览器,链接如下: http ...

  4. WPF SDK研究 之 AppModel

    Jianqiang's Mobile Dev Blog iOS.Android.WP CnBlogs Home New Post Contact Admin Rss Posts - 528 Artic ...

  5. 2015国产犯罪传记《暴力天使》HD720P.泰语中字

    导演: 吴强编剧: 阮明玉主演: 张玉英 / 金理 / 至宝类型: 传记语言:泰语制片国家/地区: 中国大陆上映日期: 2016年3月25日片长: 92分钟又名: Huong Ga暴力天使的剧情简介 ...

  6. Linux基础入门

    第一节,linux系统简介 一.实验内容 了解 Linux 的历史,Linux 与 Windows 的区别等入门知识. 二.实验要求 阅读linux简介与历史 三.实验步骤 (一).Linux 为何物 ...

  7. 学习Java第一卷--态度的转变

    你对自己的未来有什么规划?做了哪些准备? 认真学习,修身养性,做自己感兴趣的,在大学一定学好Java,将自己的专业学好学精. 我觉得未来十几年或几十年是自己无法完全控制的,只有自己朝着自己心中的目标努 ...

  8. 微信第一个“小程序”亮相:不是APP胜似APP!

    前天晚上,微信终于推出了“小程序”功能.看过效果演示之后,网友表示,好多App可以卸载了! 据了解,微信“小程序”已首批开放给200名拥有微信服务号的开发者进行内测,而且目前开发者发布的小程序无法在用 ...

  9. js事件代理

    需要注意的blog:http://blog.csdn.net/majian_1987/article/details/8591385 一篇博客看懂  http://blog.csdn.net/maji ...

  10. [C#]AES加密算法实现

    密码学中的高级加密标准(Advanced Encryption Standard,AES),又称Rijndael加密法,是美国联邦政府采用的一种区块加密标准.这个标准用来替代原先的DES,已经被多方分 ...