直播系统代码,点击产生动画效果并移动的特效
直播系统代码,点击产生动画效果并移动的特效
实现方式
1 | TranslateAnimation translateAnimation = new TranslateAnimation(<br> TranslateAnimation.RELATIVE_TO_SELF, -1, TranslateAnimation.RELATIVE_TO_SELF, 0,<br> //0代表控件本身的位置<br> TranslateAnimation.RELATIVE_TO_SELF, 0, TranslateAnimation.RELATIVE_TO_SELF, 0);<br> translateAnimation.setDuration(900);<br> mViewReward.startAnimation(translateAnimation); |
dmeo
1 | <?xml version= "1.0" encoding= "utf-8" ?><br><androidx.constraintlayout.widget.ConstraintLayout xmlns:android= "http://schemas.android.com/apk/res/android" <br> xmlns:app= "http://schemas.android.com/apk/res-auto" <br> xmlns:tools= "http://schemas.android.com/tools" <br> android:layout_width= "match_parent" <br> android:layout_height= "match_parent" <br> tools:context= ".MainActivity" ><br> <androidx.constraintlayout.widget.ConstraintLayout<br> app:layout_constraintLeft_toLeftOf= "parent" <br> android:id= "@+id/reward_view" <br> app:layout_constraintBottom_toTopOf= "@id/reward" <br> android:layout_marginBottom= "100dp" <br> android:visibility= "gone" <br> android:layout_width= "wrap_content" <br> android:layout_height= "wrap_content" ><br> <ImageView<br> android:id= "@+id/left_image" <br> app:layout_constraintLeft_toLeftOf= "parent" <br> app:layout_constraintTop_toTopOf= "parent" <br> android:layout_width= "60dp" <br> android:layout_height= "60dp" /><br> <TextView<br> android:id= "@+id/tv" <br> app:layout_constraintLeft_toRightOf= "@id/left_image" <br> app:layout_constraintTop_toTopOf= "@id/left_image" <br> app:layout_constraintBottom_toBottomOf= "@id/left_image" <br> android:layout_marginLeft= "10dp" <br> android:text= "穿云箭" <br> android:textSize= "14sp" <br> android:textColor= "#000000" <br> android:layout_width= "wrap_content" <br> android:layout_height= "wrap_content" /><br> <ImageView<br> android:id= "@+id/right_image" <br> app:layout_constraintLeft_toRightOf= "@id/tv" <br> app:layout_constraintTop_toTopOf= "parent" <br> android:layout_marginLeft= "10dp" <br> android:layout_width= "60dp" <br> android:layout_height= "60dp" /><br> <TextView<br> android:id= "@+id/number" <br> android:gravity= "center" <br> android:textSize= "30sp" <br> android:textColor= "#FF5722" <br> app:layout_constraintLeft_toRightOf= "@id/right_image" <br> app:layout_constraintTop_toTopOf= "parent" <br> android:text= "x90" <br> app:layout_constraintBottom_toBottomOf= "parent" <br> android:layout_width= "60dp" <br> android:layout_height= "0dp" /><br> </androidx.constraintlayout.widget.ConstraintLayout><br> <Button<br> android:id= "@+id/reward" <br> app:layout_constraintTop_toTopOf= "parent" <br> app:layout_constraintBottom_toBottomOf= "parent" <br> android:layout_width= "match_parent" <br> android:layout_height= "wrap_content" /><br></androidx.constraintlayout.widget.ConstraintLayout><br> public class MainActivity extends AppCompatActivity implements View.OnClickListener {<br> private ImageView mImageLeft;<br> private TextView mTv;<br> private ImageView mImageRight;<br> private TextView mNumber;<br> private Button mReward;<br> private ConstraintLayout mViewReward;<br> @Override<br> protected void onCreate(Bundle savedInstanceState) {<br> super.onCreate(savedInstanceState);<br> setContentView(R.layout.activity_main);<br> initView();<br> }<br> private void initView() {<br> mImageLeft = (ImageView) findViewById(R.id.left_image);<br> mTv = (TextView) findViewById(R.id.tv);<br> mImageRight = (ImageView) findViewById(R.id.right_image);<br> mNumber = (TextView) findViewById(R.id.number);<br> mReward = (Button) findViewById(R.id.reward);<br> mReward.setOnClickListener(this);<br> mViewReward = (ConstraintLayout) findViewById(R.id.reward_view);<br> Glide.with(this).load( "https://avatar.csdnimg.cn/E/C/F/1_weixin_45680654_1609595020.jpg" )<br> .apply(RequestOptions.bitmapTransform( new CircleCrop()))<br> .into(mImageLeft);<br> Glide.with(this).load( "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fww4.sinaimg.cn%2Flarge%2F9150e4e5ly1fhhjs6mu89j20hs0hsqdk.jpg&refer=http%3A%2F%2Fwww.sina.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1632467419&t=cb6ff9f1c7d67e67ffc7c9984cbb3daa" )<br> .apply(RequestOptions.bitmapTransform( new CircleCrop()))<br> .into(mImageRight);<br> }<br> private CountDownTimer countDownTimer = new CountDownTimer(3000,1000) {<br> @Override<br> public void onTick(long millisUntilFinished) {<br> }<br> @Override<br> public void onFinish() {<br> TranslateAnimation translateAnimation = new TranslateAnimation(<br> TranslateAnimation.RELATIVE_TO_SELF, 0, TranslateAnimation.RELATIVE_TO_SELF, -1,<br> //0代表控件本身的位置<br> TranslateAnimation.RELATIVE_TO_SELF, 0, TranslateAnimation.RELATIVE_TO_SELF, 0);<br> translateAnimation.setDuration(900);<br> mViewReward.startAnimation(translateAnimation);<br> new Handler().postDelayed( new Runnable() {<br> @Override<br> public void run() {<br> mViewReward.setVisibility(View.GONE);<br> }<br> },800);<br> }<br> };<br> @Override<br> public void onClick(View v) {<br> switch (v.getId()) {<br> case R.id.reward:<br> // TODO 21/08/25<br> Random ra = new Random();<br> int i = ra.nextInt(101 - 10) + 10;<br> mNumber.setText( "x" +i);<br> mViewReward.setVisibility(View.VISIBLE);<br> TranslateAnimation translateAnimation = new TranslateAnimation(<br> TranslateAnimation.RELATIVE_TO_SELF, -1, TranslateAnimation.RELATIVE_TO_SELF, 0,<br> //0代表控件本身的位置<br> TranslateAnimation.RELATIVE_TO_SELF, 0, TranslateAnimation.RELATIVE_TO_SELF, 0);<br> translateAnimation.setDuration(900);<br> mViewReward.startAnimation(translateAnimation);<br> countDownTimer.start();<br> break ;<br> default :<br> break ;<br> }<br> }<br> @Override<br> protected void onDestroy() {<br> if (countDownTimer!=null){<br> countDownTimer.cancel();<br> }<br> super.onDestroy();<br> } |
以上就是 直播系统代码,点击产生动画效果并移动的特效,更多内容欢迎关注之后的文章
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现