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. C语言 读取文件中特定数据

    //读取文件数据 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> struct jia ...

  2. windows 批处理把所有java源码导入一个txt文件中

    首先在src下搜*.java,把搜到的文件全拷出来放在allsrc目录下, 然后在allsrc目录下建个run.bat,键入以下内容for %%i in (*.java)  do type %%i&g ...

  3. [CareerCup] 2.4 Partition List 划分链表

    2.4 Write code to partition a linked list around a value x, such that all nodes less than x come bef ...

  4. [CareerCup] 6.5 Drop Eggs 扔鸡蛋问题

    6.5 There is a building of 100 floors. If an egg drops from the Nth floor or above, it will break. I ...

  5. mysql慢查询分析工作pt-query-digest的使用

    一.简单安装 wget percona.com/get/pt-query-digest chmoe u+x pt-query-digest 二.简单使用 ./pt-query-digest /var/ ...

  6. 小白学习mysql之优化基础(EXPLAIN的连接类型)

    ## 导语很多情况下,有很多人用各种select语句查询到了他们想要的数据后,往往便以为工作圆满结束了.这些事情往往发生在一些学生亦或刚入职场但之前又没有很好数据库基础的小白身上,但所谓闻道有先后,只 ...

  7. 求根号m(巴比伦算法)

    巴比伦算法是针对求根号m的近似值情况的,它的思想是这样的: 设根号m=X0,则如果枚举有答案X(X<X0),则m/X>X0,当精度要求不高的时候,我们可以看成X=m/X=X0,而如果精度要 ...

  8. Bootstrap3.0学习第二十五轮(JavaScript插件——折叠)

    详情请查看http://aehyok.com/Blog/Detail/31.html 个人网站地址:aehyok.com QQ 技术群号:206058845,验证码为:aehyok 本文文章链接:ht ...

  9. UITableViewdataSourse的协议所有方法

    UITableViewDataSource @required- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection ...

  10. 每天一个linux命令(34):kill命令

    Linux 中的kill命令用来终止指定的进程(terminate a process)的运行,是Linux下进程管理的常用命令.通常,终止一个前台进程可以 使用Ctrl+C键,但是,对于一个后台进程 ...