最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android如何使用圓形揭露動(dòng)畫(huà)巧妙地隱藏或顯示View詳解

 更新時(shí)間:2022年04月28日 15:50:30   作者:QiShare  
Android開(kāi)發(fā)中會(huì)遇到不少顯示和隱藏的問(wèn)題,下面這篇文章主要給大家介紹了關(guān)于Android如何使用圓形揭露動(dòng)畫(huà)巧妙地隱藏或顯示View的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下

1.引言

在開(kāi)發(fā)過(guò)程中,我們經(jīng)常會(huì)遇到需要顯示或隱藏View視圖的情況,如果在隱藏或顯示View的過(guò)程中加上動(dòng)畫(huà),能讓交互更加的友好和動(dòng)感,本文將介紹如何使用圓形揭露動(dòng)畫(huà)巧妙地隱藏或顯示View。

2.圓形揭露動(dòng)畫(huà)簡(jiǎn)介

圓形揭露動(dòng)畫(huà)是動(dòng)畫(huà)的一種,是由ViewAnimationUtils類提供的,調(diào)用ViewAnimationUtils.createCircularReveal()方法可以創(chuàng)建圓形揭露動(dòng)畫(huà),使用此動(dòng)畫(huà)要求API級(jí)別為21及以上版本,createCircularReveal()方法的參數(shù)如下:

//view:使用圓形動(dòng)畫(huà)的視圖
//centerX:裁剪圓形的中心的X坐標(biāo),這個(gè)中心是指相對(duì)于視圖本身
//centerY:裁剪圓形的中心的Y坐標(biāo),這個(gè)中心是指相對(duì)于視圖本身
//startRadius:圓形的起始半徑
//endRadius:圓形的結(jié)束半徑
public static Animator createCircularReveal(View view,int centerX,  int centerY, float startRadius, float endRadius)

3.使用圓形揭露動(dòng)畫(huà)隱藏或顯示View

3.1 簡(jiǎn)易布局

簡(jiǎn)易布局如下:

<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:gravity="center_horizontal"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <Button
        android:id="@+id/btn_hide_or_show"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="隱藏或顯示"
        android:textColor="@color/black"
        android:textSize="18sp" />

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_marginTop="50dp"
        android:src="@mipmap/ic_launcher"/>
</LinearLayout>

3.2 使用圓形揭露動(dòng)畫(huà)隱藏View

首先要計(jì)算得出View相對(duì)于自身的中心點(diǎn)的X坐標(biāo)和Y坐標(biāo),然后調(diào)用Math.hypot()方法計(jì)算得出圓形的半徑,接著調(diào)用ViewAnimationUtils.createCircularReveal(imageView, ivXCenter, ivYCenter, circleRadius, 0f)創(chuàng)建圓形揭露動(dòng)畫(huà),增加動(dòng)畫(huà)執(zhí)行的Listener,在動(dòng)畫(huà)執(zhí)行結(jié)束后調(diào)用imageView.setVisibility(View.GONE),最后啟動(dòng)動(dòng)畫(huà),示例如下:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
     int width = imageView.getWidth();
     int height = imageView.getHeight();
     int ivXCenter = width/2;
     int ivYCenter = height/2;
     float circleRadius = (float) Math.hypot(ivXCenter, ivYCenter);
     Animator circularReveal = ViewAnimationUtils.createCircularReveal(imageView, ivXCenter, ivYCenter, circleRadius, 0f);
     circularReveal.addListener(new AnimatorListenerAdapter() {
         @Override
         public void onAnimationEnd(Animator animation) {
             super.onAnimationEnd(animation);
             imageView.setVisibility(View.GONE);
             isVisible = false;
         }
     });
     circularReveal.start();
 }else {
     imageView.setVisibility(View.GONE);
     isVisible = false;
 }

3.3 使用圓形揭露動(dòng)畫(huà)顯示View

使用圓形揭露動(dòng)畫(huà)顯示View,先計(jì)算得出View相對(duì)于自身的中心點(diǎn)的X坐標(biāo)和Y坐標(biāo),然后算出圓形的半徑,接著創(chuàng)建圓形揭露動(dòng)畫(huà),此時(shí)的起始半徑是0f,結(jié)束半徑是圓形的半徑,調(diào)用imageView.setVisibility(View.VISIBLE),最后啟動(dòng)動(dòng)畫(huà),示例如下:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    int width = imageView.getWidth();
    int height = imageView.getHeight();
    int ivXCenter = width/2;
    int ivYCenter = height/2;
    float circleRadius = (float) Math.hypot(ivXCenter, ivYCenter);
    Animator circularReveal = ViewAnimationUtils.createCircularReveal(imageView, ivXCenter, ivYCenter, 0f, circleRadius);
    imageView.setVisibility(View.VISIBLE);
    isVisible = true;
    circularReveal.start();
}else {
    imageView.setVisibility(View.VISIBLE);
    isVisible = true;
}

4.總結(jié)

使用圓形揭露動(dòng)畫(huà)隱藏或顯示View,主要是計(jì)算出View相對(duì)于自身的中心點(diǎn)的X坐標(biāo)和Y坐標(biāo),并計(jì)算出圓形半徑,在調(diào)用ViewAnimationUtils.createCircularReveal()方法創(chuàng)建的時(shí)候要注意起始半徑和結(jié)束半徑的填寫(xiě),隱藏View的時(shí)候在動(dòng)畫(huà)執(zhí)行完畢后setVisibility()方法隱藏,顯示View的時(shí)候,在動(dòng)畫(huà)啟動(dòng)前調(diào)用setVisibility()方法顯示。

到此這篇關(guān)于Android如何使用圓形揭露動(dòng)畫(huà)巧妙地隱藏或顯示View的文章就介紹到這了,更多相關(guān)Android隱藏或顯示View內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

麟游县| 印江| 文化| 神池县| 汤原县| 遂川县| 辉县市| 来凤县| 绍兴县| 新蔡县| 威信县| 敖汉旗| 临桂县| 南江县| 会东县| 岳普湖县| 张北县| 滁州市| 辉南县| 德惠市| 盐边县| 清流县| 宜兰县| 桓台县| 林甸县| 高尔夫| 威宁| 西充县| 西盟| 图片| 乌拉特后旗| 邵武市| 乃东县| 梅河口市| 成武县| 浑源县| 兴和县| 比如县| 呼和浩特市| 潞西市| 丹江口市|