直播系統程式碼,點選產生動畫效果並移動的特效

zhibo系統開發發表於2021-12-28

直播系統程式碼,點選產生動畫效果並移動的特效

實現方式

go
TranslateAnimation translateAnimation = new TranslateAnimation(
                        TranslateAnimation.RELATIVE_TO_SELF, -1, TranslateAnimation.RELATIVE_TO_SELF, 0,
                        //0代表控制元件本身的位置
                        TranslateAnimation.RELATIVE_TO_SELF, 0, TranslateAnimation.RELATIVE_TO_SELF, 0);
                translateAnimation.setDuration(900);
                mViewReward.startAnimation(translateAnimation);



dmeo


```go
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="
    xmlns:app="
    xmlns:tools="
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">
    <androidx.constraintlayout.widget.ConstraintLayout
        app:layout_constraintLeft_toLeftOf="parent"
        android:id="@+id/reward_view"
        app:layout_constraintBottom_toTopOf="@id/reward"
        android:layout_marginBottom="100dp"
        android:visibility="gone"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <ImageView
            android:id="@+id/left_image"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            android:layout_width="60dp"
            android:layout_height="60dp"/>
        <TextView
            android:id="@+id/tv"
            app:layout_constraintLeft_toRightOf="@id/left_image"
            app:layout_constraintTop_toTopOf="@id/left_image"
            app:layout_constraintBottom_toBottomOf="@id/left_image"
            android:layout_marginLeft="10dp"
            android:text="穿雲箭"
            android:textSize="14sp"
            android:textColor="#000000"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
        <ImageView
            android:id="@+id/right_image"
            app:layout_constraintLeft_toRightOf="@id/tv"
            app:layout_constraintTop_toTopOf="parent"
            android:layout_marginLeft="10dp"
            android:layout_width="60dp"
            android:layout_height="60dp"/>
        <TextView
            android:id="@+id/number"
            android:gravity="center"
            android:textSize="30sp"
            android:textColor="#FF5722"
            app:layout_constraintLeft_toRightOf="@id/right_image"
            app:layout_constraintTop_toTopOf="parent"
            android:text="x90"
            app:layout_constraintBottom_toBottomOf="parent"
            android:layout_width="60dp"
            android:layout_height="0dp"/>
    </androidx.constraintlayout.widget.ConstraintLayout>
    <Button
        android:id="@+id/reward"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
</androidx.constraintlayout.widget.ConstraintLayout>
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    private ImageView mImageLeft;
    private TextView mTv;
    private ImageView mImageRight;
    private TextView mNumber;
    private Button mReward;
    private ConstraintLayout mViewReward;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }
    private void initView() {
        mImageLeft = (ImageView) findViewById(R.id.left_image);
        mTv = (TextView) findViewById(R.id.tv);
        mImageRight = (ImageView) findViewById(R.id.right_image);
        mNumber = (TextView) findViewById(R.id.number);
        mReward = (Button) findViewById(R.id.reward);
        mReward.setOnClickListener(this);
        mViewReward = (ConstraintLayout) findViewById(R.id.reward_view);
        Glide.with(this).load("https://avatar.csdnimg.cn/E/C/F/1_weixin_45680654_1609595020.jpg")
                .apply(RequestOptions.bitmapTransform(new CircleCrop()))
                .into(mImageLeft);
        Glide.with(this).load("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fww4.sinaimg.cn%2Flarge%2F9150e4e5ly1fhhjs6mu89j20hs0hsqdk.jpg&refer=http%3A%2F%2F)
                .apply(RequestOptions.bitmapTransform(new CircleCrop()))
                .into(mImageRight);
    }
    private CountDownTimer countDownTimer = new CountDownTimer(3000,1000) {
        @Override
        public void onTick(long millisUntilFinished) {
        }
        @Override
        public void onFinish() {
            TranslateAnimation translateAnimation = new TranslateAnimation(
                    TranslateAnimation.RELATIVE_TO_SELF, 0, TranslateAnimation.RELATIVE_TO_SELF, -1,
                    //0代表控制元件本身的位置
                    TranslateAnimation.RELATIVE_TO_SELF, 0, TranslateAnimation.RELATIVE_TO_SELF, 0);
            translateAnimation.setDuration(900);
            mViewReward.startAnimation(translateAnimation);
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    mViewReward.setVisibility(View.GONE);
                }
            },800);
        }
    };
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.reward:
                // TODO 21/08/25
                Random ra =new Random();
                int i = ra.nextInt(101 - 10) + 10;
                mNumber.setText("x"+i);
                mViewReward.setVisibility(View.VISIBLE);
                TranslateAnimation translateAnimation = new TranslateAnimation(
                        TranslateAnimation.RELATIVE_TO_SELF, -1, TranslateAnimation.RELATIVE_TO_SELF, 0,
                        //0代表控制元件本身的位置
                        TranslateAnimation.RELATIVE_TO_SELF, 0, TranslateAnimation.RELATIVE_TO_SELF, 0);
                translateAnimation.setDuration(900);
                mViewReward.startAnimation(translateAnimation);
                countDownTimer.start();
                break;
            default:
                break;
        }
    }
    @Override
    protected void onDestroy() {
        if (countDownTimer!=null){
            countDownTimer.cancel();
        }
        super.onDestroy();
    }


以上就是 直播系統程式碼,點選產生動畫效果並移動的特效,更多內容歡迎關注之後的文章


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69978258/viewspace-2849706/,如需轉載,請註明出處,否則將追究法律責任。

相關文章