介绍
今天就跟大家聊聊有关Android开发中使用视图实现一个旋转音乐专辑功能,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。
具体内容如下
<强>三。关键代码强>
1。圆形背景
& lt;及# 63;xml version=?.0”;编码=皍tf-8", # 63;比; http://schemas.android.com/apk/res/android" & lt;形状xmlns: android=?; android:形状=皁val"比; 大小& lt; android:宽度=? dp" android:身高=? dp"/比; & lt;固体android:颜色=? 1 affffff"/比; & lt;/shape>
2。旋转的方形图片
//设置旋转动画(属性动画) 私人空间init(上下文语境){ 视图。充气(上下文,出来。view_rotate_album,); ivAlbumPic=(ImageView) findViewById (R.id.view_pic); 动画师=ObjectAnimator。ofFloat (ivAlbumPic“rotation" 0.0 f, 360.0度); 动画师。setDuration (10 * 1000); 动画师。setInterpolator(新LinearInterpolator ()); animator.setRepeatCount (ObjectAnimator.INFINITE); animator.setRepeatMode (ValueAnimator.RESTART); setPlaying(真正的); }//更新播放状态 公共空间setPlaying(布尔isPlaying) { 日志。d(标签,“更新RotateAlbumView: isPlaying=?+ isPlaying); 如果(isPlaying) { 如果(! animator.isRunning ()) { animator.start (); 其他}{ animator.resume (); } 其他}{ 如果(! animator.isStarted () | | ! animator.isRunning ()) { animator.cancel (); } animator.pause (); } }
3。渐变圆环
公共类WidgetAlbumBgView扩展视图{ 私人油漆涂料;//圆环半径 私人int ringWidth;//渐变色 私人int[]颜色; 私人SweepGradient梯度;//圆线距圆环内边的距离 私人int [] ringLinesMarginOut={ dp2px(3.78度), dp2px(7.03度), dp2px(10.27度), dp2px(12.97度) };//圆线高度 私人int ringLineWidth; 公共WidgetAlbumBgView(上下文语境){ 这(上下文,null); } 公共WidgetAlbumBgView(上下文语境,@Nullable AttributeSet attrs) { 这(上下文、attrs 0); } 公共WidgetAlbumBgView(上下文语境,@Nullable AttributeSet attrs, int defStyleAttr) { 超级(上下文、attrs defStyleAttr); init(上下文,attrs); } 私人空间init(上下文语境,AttributeSet attrs) { 涂=new (); paint.setAntiAlias(真正的); paint.setStyle (Paint.Style.STROKE); paint.setStrokeCap (Paint.Cap.ROUND); 颜色=new int[]{色鬼(R.color.widget_album_ring_color1),色鬼(R.color.widget_album_ring_color2), 色鬼(R.color.widget_album_ring_color1),色鬼(R.color.widget_album_ring_color2), 色鬼(R.color.widget_album_ring_color1)}; TypedArray TypedArray=上下文。obtainStyledAttributes (attrs R.styleable.WidgetAlbumBgView); ringWidth=(int) typedArray.getDimension (R.styleable。WidgetAlbumBgView_ring_width getresource () .getDimension (R.dimen.widget_album_ring_width)); ringLineWidth=(int) typedArray.getDimension (R.styleable。WidgetAlbumBgView_ring_line_width getresource () .getDimension (R.dimen.widget_album_ring_line_width)); typedArray.recycle (); } @Override 保护空白> & lt; RelativeLayout xmlns: android=癶ttp://schemas.android.com/apk/res/android" xmlns:工具=癶ttp://schemas.android.com/tools" android: layout_width=癅dimen/widget_album_size_vertical" android: layout_height=癅dimen/widget_album_size_vertical" android:背景=癅drawable/rotate_album_bg"比; & lt; ImageView android: id=癅 + id/view_pic" android: layout_width=癅dimen/widget_album_pic_size" android: layout_height=癅dimen/widget_album_pic_size" android: layout_centerInParent=皌rue" android: scaleType=癱enterInside" android: src=https://www.yisu.com/zixun/" @mipmap/ic_qifenle "/>Android开发中使用视图实现一个旋转音乐专辑功能