Android开发之Activity全透明渐变切换方法

所属分类: 软件编程 / Android 阅读数: 55
收藏 0 赞 0 分享

Activity全透明渐变切换

类似于Dialog的显示动画效果一样

1. 先设置Acitivity为去透明,在取消掉Activity默认的切换动画

 <style name="AppTheme2" parent="Theme.AppCompat.Light">
  <!-- Customize your theme here. -->
  <item name="windowNoTitle">true</item>
  <item name="colorPrimary">@color/colorPrimary</item>
  <item name="colorPrimaryDark">@color/tabbackground</item>
  <item name="colorAccent">@color/colorAccent</item>
   <item name="android:windowBackground">@color/transparent</item>//这个之时全透明
  <item name="android:windowIsTranslucent">true</item>
  <item name="android:windowAnimationStyle">@style/activityanimation</item>
 </style>
 <style name="activityanimation" >
  <item name="android:activityOpenEnterAnimation">@null</item>
  <item name="android:activityOpenExitAnimation">@null</item>
  <item name="android:activityCloseEnterAnimation">@null</item>
  <item name="android:activityCloseExitAnimation">@null</item>
 </style>

2. 设置渐变动画:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/ll"
 android:orientation="vertical"
 android:layout_width="match_parent"
 android:background="#000"
 android:layout_height="match_parent">
 <MyImageView
  android:layout_width="match_parent"
  android:layout_height="300dp"
  android:layout_centerInParent="true"
  android:clickable="true"
  android:background="@mipmap/meinv"/>
</RelativeLayout>
public class Activitytwo extends AppCompatActivity{
 private int tran=0x00000000;
 private int end=0x88000000;
 private RelativeLayout ll;
 @Override
 protected void onCreate(@Nullable Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
  setContentView(R.layout.ativity);
  ll = (RelativeLayout) findViewById(R.id.ll);
  returnposition();
  ll.setOnClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View v) {
    finish();
   }
  });
 }
 public void returnposition()
 {
  ValueAnimator colorAnim = ObjectAnimator.ofInt(ll, "backgroundColor", tran, end);
  colorAnim.setDuration(300);
  colorAnim.setEvaluator(new ArgbEvaluator());
  colorAnim.start();
 }

 @Override
 public void finish() {
  ValueAnimator colorAnim = ObjectAnimator.ofInt(ll, "backgroundColor", end, tran);
  colorAnim.setDuration(300);
  colorAnim.setEvaluator(new ArgbEvaluator());
  colorAnim.start();
  super.finish();
 }
}

以上这篇Android开发之Activity全透明渐变切换方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。

更多精彩内容其他人还在看

Android网络编程之获取网络上的Json数据实例

这篇文章主要介绍了Android网络编程之获取网络上的Json数据实例,本文用完整的代码实例讲解了在Android中读取网络中Json数据的方法,需要的朋友可以参考下
收藏 0 赞 0 分享

Android中的windowSoftInputMode属性详解

这篇文章主要介绍了Android中的windowSoftInputMode属性详解,本文对windowSoftInputMode的9个属性做了详细总结,需要的朋友可以参考下
收藏 0 赞 0 分享

Android网络编程之UDP通信模型实例

这篇文章主要介绍了Android网络编程之UDP通信模型实例,本文给出了服务端代码和客户端代码,需要的朋友可以参考下
收藏 0 赞 0 分享

Android中使用ListView实现漂亮的表格效果

这篇文章主要介绍了Android中使用ListView实现漂亮的表格效果,本文用详细的代码实例创建了一个股票行情表格,需要的朋友可以参考下
收藏 0 赞 0 分享

Android中刷新界面的二种方法

这篇文章主要介绍了Android中刷新界面的二种方法,本文使用Handler、postInvalidate两种方法实现界面刷新,需要的朋友可以参考下
收藏 0 赞 0 分享

Android SDK三种更新失败及其解决方法

这篇文章主要介绍了Android SDK三种更新失败及其解决方法,需要的朋友可以参考下
收藏 0 赞 0 分享

Android学习笔记——Menu介绍(一)

Android3.0(API level 11)开始,Android设备不再需要专门的菜单键。随着这种变化,Android app应该取消对传统6项菜单的依赖。取而代之的是提供anction bar来提供基本的用户功能
收藏 0 赞 0 分享

Android学习笔记——Menu介绍(二)

这次将继续上一篇文章没有讲完的Menu的学习,上下文菜单(Context menu)和弹出菜单(Popup menu)
收藏 0 赞 0 分享

Android学习笔记——Menu介绍(三)

今天继续昨天没有讲完的Menu的学习,主要是Popup Menu的学习,需要的朋友可以参考下
收藏 0 赞 0 分享

Android显示网络图片实例

这篇文章主要介绍了Android显示网络图片的方法,以实例形式展示了Android程序显示网络图片的方法,非常具有实用价值,需要的朋友可以参考下
收藏 0 赞 0 分享
查看更多