web-dev-qa-db-ja.com

android

10秒後にimageViewが表示されなくなりました(mainActivityのチュートリアル画像)。しかし、このように見栄えがよくないので、スムーズなフェードアウトを行いたいのですが、誰かが私に良いチュートリアルを紹介してもらえますか

     img=(ImageView)findViewById(R.id.ImageTutorial);
    if(getIntent()!=null)
    {

        Bundle extras = getIntent().getExtras();
        String TutorialDemo=extras !=null? extras.getString("TutorialDemo"):"false";

        if(TutorialDemo.equals("true"))
        {
            Runnable mRunnable;
            Handler mHandler=new Handler();

            mRunnable=new Runnable() {

                        @Override
                        public void run() {

                            img.setVisibility(View.GONE); //This will remove the View. and free s the space occupied by the View    
                        }
                    };
                    mHandler.postDelayed(mRunnable,10*900);
        }
        else
        {
            img.setVisibility(View.GONE);
        }
         }

ここに画像ビューのXMLがあります

  <?xml version="1.0" encoding="utf-8"?>
  <ScrollView xmlns:Android="http://schemas.Android.com/apk/res/Android"
  xmlns:tools="http://schemas.Android.com/tools"
  Android:layout_width="match_parent"
 Android:layout_height="match_parent" 
 Android:id="@+id/fullview"
>

<LinearLayout
    Android:layout_width="match_parent"
    Android:layout_height="match_parent"
    Android:layout_margin="10dp"
    Android:orientation="vertical" >

      .
      .
      .
      .

    <ImageView
        Android:contentDescription="tutorial"
        Android:id="@+id/ImageTutorial"
        Android:layout_width="match_parent"
        Android:layout_height="120dp"
        Android:layout_alignParentBottom="true"
        Android:background="@drawable/tutorial"
        Android:layout_marginTop="40dp"
        Android:gravity="center"
        />

</LinearLayout>
16
denza

コードのimg.setVisibility(View.GONE)を、次のように定義されているfadeOutAndHideImage(img)の呼び出しに置き換えます。

  private void fadeOutAndHideImage(final ImageView img)
  {
    Animation fadeOut = new AlphaAnimation(1, 0);
    fadeOut.setInterpolator(new AccelerateInterpolator());
    fadeOut.setDuration(1000);

    fadeOut.setAnimationListener(new AnimationListener()
    {
            public void onAnimationEnd(Animation animation) 
            {
                  img.setVisibility(View.GONE);
            }
            public void onAnimationRepeat(Animation animation) {}
            public void onAnimationStart(Animation animation) {}
    });

    img.startAnimation(fadeOut);
}

最初にフェードアウトアニメーションを適用し、次にイメージビューを非表示にします。

53
Const

このコードスニペットからヒントを取得します。必要なコードは次のようになります

Animation fadeOut = new AlphaAnimation(1, 0);  // the 1, 0 here notifies that we want the opacity to go from opaque (1) to transparent (0)
fadeOut.setInterpolator(new AccelerateInterpolator());
fadeOut.setStartOffset(500); // Start fading out after 500 milli seconds
fadeOut.setDuration(1000); // Fadeout duration should be 1000 milli seconds

これを画像ビューと言う要素に設定します-

myImageView.setAnimation(fadeOut);
6