Android activity从下渐渐往上弹出代码

MainActivity

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

public class MainActivity extends AppCompatActivity {



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

    }
    public void openActivity(View v) {
        Intent intent = new Intent(this, OtherActivity.class);
        startActivity(intent);
        //屏幕动画弹入效果切换,调用anim文件夹中创建的enteralpha(进入动画)和exitalpha(淡出动画)两个动画(注意:两个xml文件命名不能有大写字母)
        //如果想定义其他动画效果,只需要改变enteralpha和exitalpha两个文件
        this.overridePendingTransition(R.anim.enteralpha, R.anim.exitalpha);
    }


}
 
OtherActivity
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

public class OtherActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_other);
    }
    public void openActivitya(View v) {
        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
        //屏幕动画弹入效果切换,调用anim文件夹中创建的enteralpha(进入动画)和exitalpha(淡出动画)两个动画(注意:两个xml文件命名不能有大写字母)
        //如果想定义其他动画效果,只需要改变enteralpha和exitalpha两个文件
        this.overridePendingTransition(R.anim.enteralpha, R.anim.exitalpha);
    }


}
anim
调用anim文件夹中创建的enteralpha(进入动画)和exitalpha(淡出动画)两个动画(注意:两个xml文件命名不能有大写字母)
enteralpha.xml
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false"
    >
    <!-- 动画效果  从看不见到可以看见,也就是0到1,变幻时间为5000毫秒-->
   <!-- <alpha
        android:fromAlpha="0"
        android:toAlpha="1"
        android:duration="20000"
        />-->
    <!--下面这个是实现android activity 从下往上弹出的动画-->
    <translate
        android:duration="300"
        android:fromYDelta="100.0%"
        android:toYDelta="10.000002%" />
    <alpha
        android:duration="50"
        android:fromAlpha="0.0"
        android:toAlpha="1.0" />
</set>

 
exitalpha.xml
<set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false">
    <!-- 退出动画效果  从可以看见到不可以看见,也就是1.0到0,变幻时间为5000毫秒-->
   <!-- <alpha
        android:fromAlpha="1.0"
        android:toAlpha="0"
        android:duration="2000"
        />-->
<!--下面这个是实现android activity 从下往上弹出的动画-->
    <translate
        android:duration="300"
        android:fromYDelta="100.0%"
        android:toYDelta="10.000002%" />
    <alpha
        android:duration="50"
        android:fromAlpha="0.0"
        android:toAlpha="1.0" />
</set>

布局

activity_main
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.example.dell.glide_activity.MainActivity">
 
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello"
        android:onClick="openActivity"/>
</LinearLayout>
 
 
activity_other
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="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="com.example.dell.glide_activity.OtherActivity">
    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/new_activity"
        android:onClick="openActivitya"
        />


</LinearLayout>
values

strings

 
<resources>
    //这个是你的项目名
    <string name="app_name">Glide_Activity</string>

    <string name="hello">打开新Activity</string>

    <string name="new_window">新窗口</string>
    <string name="new_activity">这是新Activity</string>
</resources>






  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值