android transitiondrawable基本使用
来源:互联网 发布:战舰世界画面优化设置 编辑:程序博客网 时间:2024/04/28 18:41
一:transitiondrawable是LayerDrawable的子类,不过它只负责管理两层drawable,并且提供了一个透明度变化的动画,可以控制从一层drawable过度到另一层drawable的动画效果。
二:在drawable文件夹下:
<?xml version="1.0" encoding="utf-8"?><transition xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/lamp_off" /> <item android:drawable="@drawable/lamp_on" /></transition>
三:布局文件
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:src="@drawable/bitmap" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/iv_drawable"/> <Button android:id="@+id/btn_on" android:text="light on" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <Button android:id="@+id/btn_off" android:text="light off" android:layout_width="wrap_content" android:layout_height="wrap_content"/></LinearLayout>
四:activity
package com.example.kirito.myapplication.testdrawable;import android.graphics.drawable.TransitionDrawable;import android.os.Bundle;import android.support.annotation.Nullable;import android.support.v7.app.AppCompatActivity;import android.view.View;import android.widget.Button;import android.widget.ImageView;import com.example.kirito.myapplication.R;/** * Created by kirito on 2016.10.31. */public class TestDrawable extends AppCompatActivity implements View.OnClickListener{ private Button on,off; private ImageView iv; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.testdrawable); on = (Button) findViewById(R.id.btn_on); off = (Button) findViewById(R.id.btn_off); on.setOnClickListener(this); off.setOnClickListener(this); iv = (ImageView) findViewById(R.id.iv_drawable); } @Override public void onClick(View v) { if (v.getId() == R.id.btn_off){ TransitionDrawable drawable = (TransitionDrawable) iv.getDrawable(); //从第二个item切换到第一个item drawable.reverseTransition(3000); }else if (v.getId() == R.id.btn_on){ TransitionDrawable drawable = (TransitionDrawable) iv.getDrawable(); //从第一个item切换到第二个item drawable.startTransition(3000); } }}
五:实现关灯,开灯的效果
0 0
- android transitiondrawable基本使用
- Android TransitionDrawable&StateListDrawable的使用
- Android 中TransitionDrawable的使用
- Android 中TransitionDrawable的使用
- android TransitionDrawable
- Android TransitionDrawable ImageView过度效果使用实例
- Android TransitionDrawable ImageView过度效果使用实例
- 6.6 Android Framework - TransitionDrawable
- Android Drawable之TransitionDrawable
- Android Drawable之TransitionDrawable
- TransitionDrawable的使用
- TransitionDrawable的使用
- TransitionDrawable 使用详解
- TransitionDrawable
- TransitionDrawable
- Android--TransitionDrawable-淡入淡出效果
- Android TransitionDrawable:过渡动画Drawable
- 使用TransitionDrawable实现渐变效果
- java.util.Scanner
- linux c 通过内存映射,操作文件
- BeanFactoryAware在InitializingBean之后执行,奇怪的Spring初始化顺序?
- ios中由UITabbar管理的UINavigationController当push的时候隐藏TabBar
- 个人记录-LeetCode 17. Letter Combinations of a Phone Number
- android transitiondrawable基本使用
- 关于多层级树形结构的项目列表
- 母函数训练C题 HDU 1085
- servlet小记
- 【GMT】Ubuntu16.04下安装GMT5.2.1报错non-floating-point argument in call to function __builtin_isnan
- 前行
- redis的常用命令
- linux c 实现rm命令
- hdu 5952 Counting Cliques 2016ACM/ICPC沈阳赛区现场赛E