首页 > 解决方案 > 如何在图像视图中显示的图库中选择图像上添加扫描动画。指纹扫描等动画

问题描述

   <ImageView
            android:id="@+id/imageView"
            android:layout_width="100dp"
            android:layout_height="30dp"
            android:layout_marginLeft="10dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:srcCompat="@drawable/gallery" />

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/image"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"

app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<ImageView
    android:id="@+id/imageView3"
    android:layout_width="354dp"
    android:layout_height="211dp"
    android:layout_marginEnd="8dp"
    android:layout_marginRight="8dp"
    android:layout_marginTop="16dp"
    android:layout_weight="1"
    android:contentDescription="TODO"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.514"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<View
    android:id="@+id/bar"
    android:layout_width="200dp"
    android:layout_height="6dp"
    android:background="#da2831"
    android:visibility="gone"

 />

Java 代码
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_imagetotext);

    LinearLayout imageView = (LinearLayout) findViewById(R.id.image);


    final View bar = findViewById(R.id.bar);
    final Animation animation = 
    AnimationUtils.loadAnimation(Imagetotext.this,  R.anim.anim);
    animation.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {}

        @Override
        public void onAnimationEnd(Animation animation) {
            bar.setVisibility(View.GONE);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {}
    });

    imageView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
          //  bar.setVisibility(View.VISIBLE);
           // bar.startAnimation(animation);
            return false;
        }
    });



  btn4 = (ImageView) findViewById(R.id.imageView)
  btn4.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            Intent photoPickerIntent = newIntent(Intent.ACTION_PICK);
                    photoPickerIntent.setType("image/*");
                    startActivityForResult(photoPickerIntent, 
                 RESULT_LOAD_IMG);


        }
      });



    iv_image = (ImageView) findViewById(R.id.imageView3);

     }



 @Override
   protected void onActivityResult(int reqCode, int resultCode, Intent data) 
   {
    super.onActivityResult(reqCode, resultCode, data);

    if (resultCode == RESULT_OK) {


        try {
            final Uri imageUri = data.getData();
            final InputStream imageStream = 
       getContentResolver().openInputStream(imageUri);
            selectedImage = BitmapFactory.decodeStream(imageStream);
            iv_image.setImageBitmap(selectedImage);
            // addsticker(null);
            String[] projection = { MediaStore.Images.Media.DATA };
            Cursor cursor = managedQuery(imageUri, projection, null, null, 
      null);
            int column_index = 
      cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            cursor.moveToFirst();
            picturePath = cursor.getString(column_index);
            // createPdf();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            Toast.makeText(Imagetotext.this, "Something went wrong", 
      Toast.LENGTH_LONG).show();
        }

    }else {
        Toast.makeText(Imagetotext.this, "You haven't picked 
    Image",Toast.LENGTH_LONG).show();
    }
    }
动画.xml

 android:interpolator="@android:anim/accelerate_decelerate_interpolator"
   android:fillAfter="false">

<translate
android:fromYDelta="0%p"
android:toYDelta="100%p"
android:duration="1000"
android:repeatCount="2"
android:repeatMode="reverse"
/>

我的问题是扫描动画效果很好,但是当动画开始时,图像视图中的图像在动画结束时隐藏,图像出现。我希望在播放动画时图像对用户可见

标签: androidanimationscanning

解决方案


推荐阅读