Android 最简单动画实现(imageView,webview的进入和退出)

22 篇文章 0 订阅
1 篇文章 0 订阅

关键就这个方法

Animation myAnimation = AnimationUtils.loadAnimation(TestImageAnimactionActivity  .this,
                R.anim.trans_in);
        webView.startAnimation(myAnimation);

Activity:

public class TestImageAnimactionActivity  extends Activity {
    private Button in;
    private Button out;
    private WebView imageView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.test_image_animacation);
        findView();
        initView();
    }

    private void findView() {
        in= (Button) findViewById(R.id.test_image_animacation_in);
        out= (Button) findViewById(R.id.test_image_animacation_out);
        imageView= (WebView) findViewById(R.id.test_image_animacation_image);
        WebSettings webSettings=imageView.getSettings();
        SettingsWebViewUtils.setSettings(TestImageAnimaction.this,webSettings);
        imageView.setWebChromeClient(new WebChromeClient(){
            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                super.onProgressChanged(view, newProgress);
            }
        });
        imageView.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                return super.shouldOverrideUrlLoading(view, url);
            }
        });
        imageView.loadUrl(API.MAIN_URL);
    }

    private void initView() {
        in.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                myAnimacation(imageView,R.anim.translate_in);
            }
        });
        out.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                myAnimacation(imageView,R.anim.translate_out);
            }
        });
    }
    /*
   * 动画效果代码
   *
   * */
    public void myAnimacation(WebView webView,int animacation_id){
        Animation myAnimation = AnimationUtils.loadAnimation(TestImageAnimaction.this,
                animacation_id);
        webView.startAnimation(myAnimation);
    }
}

Layout

<?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">
    <Button
        android:id="@+id/test_image_animacation_in"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="进入"/>
    <Button
        android:id="@+id/test_image_animacation_out"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="退出"/>
    <!--<ImageView
        android:id="@+id/test_image_animacation_image"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@mipmap/ic_launcher"/>-->
    <WebView
        android:id="@+id/test_image_animacation_image"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    </WebView>
</LinearLayout>

in.xml , out.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
    <translate android:fromXDelta="100%"
                android:toXDelta="0%p"
                android:duration="1000" />
</set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
    <translate android:fromXDelta="0%"
                android:toXDelta="-100%p"
                android:duration="1000" />
</set>

哦了 效果如下

效果

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值