亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Android實現(xiàn)網(wǎng)易云音樂的旋轉(zhuǎn)專輯View

 更新時間:2020年11月19日 09:42:26   作者:dongpingwang  
這篇文章主要為大家詳細介紹了Android實現(xiàn)網(wǎng)易云音樂的旋轉(zhuǎn)專輯View,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了Android實現(xiàn)網(wǎng)易云音樂的旋轉(zhuǎn)專輯View,供大家參考,具體內(nèi)容如下

一.前言

最近做過 類似網(wǎng)易云音樂專輯唱片的效果,這里記錄下開發(fā)思路,僅供參考。但需求不完全與網(wǎng)易云音樂一樣,這個只有圖片會旋轉(zhuǎn)(網(wǎng)易云是整個磁盤都會旋轉(zhuǎn)),沒有唱片機械臂。

二.思路

如下圖,我這里是分為 圓形背景+旋轉(zhuǎn)的方形圖片+漸變圓環(huán)

三.關(guān)鍵代碼

1. 圓形背景

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"

 android:shape="oval">
 <size
  android:width="1dp"
  android:height="1dp" />
 <solid android:color="#1AFFFFFF" />
</shape>

2.旋轉(zhuǎn)的方形圖片

// 設(shè)置旋轉(zhuǎn)動畫(屬性動畫)
private void init(Context context) {
  View.inflate(context, R.layout.view_rotate_album, this);
  ivAlbumPic = (ImageView) findViewById(R.id.view_pic);
  animator = ObjectAnimator.ofFloat(ivAlbumPic, "rotation", 0.0F, 360.0F);
  animator.setDuration(10 * 1000);
  animator.setInterpolator(new LinearInterpolator());
  animator.setRepeatCount(ObjectAnimator.INFINITE);
  animator.setRepeatMode(ValueAnimator.RESTART);
  setPlaying(true);
 }

 // 更新播放狀態(tài)
 public void setPlaying(boolean isPlaying) {
  Log.d(TAG, "update RotateAlbumView: isPlaying = " + isPlaying);
  if (isPlaying) {
   if (!animator.isRunning()) {
    animator.start();
   } else {
    animator.resume();
   }
  } else {
   if (!animator.isStarted() || !animator.isRunning()) {
    animator.cancel();
   }
   animator.pause();
  }
}

3.漸變圓環(huán)

public class WidgetAlbumBgView extends View {
 private Paint paint;
 // 圓環(huán)半徑
 private int ringWidth;
 // 漸變色
 private int[] colors;
 private SweepGradient gradient;
 // 圓線距圓環(huán)內(nèi)邊的距離
 private int[] ringLinesMarginOut = {
   dp2px(3.78F),
   dp2px(7.03F),
   dp2px(10.27F),
   dp2px(12.97F)
 };
 // 圓線高度
 private int ringLineWidth;

 public WidgetAlbumBgView(Context context) {
  this(context, null);
 }

 public WidgetAlbumBgView(Context context, @Nullable AttributeSet attrs) {
  this(context, attrs, 0);
 }

 public WidgetAlbumBgView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
  super(context, attrs, defStyleAttr);
  init(context, attrs);
 }

 private void init(Context context, AttributeSet attrs) {
  paint = new Paint();
  paint.setAntiAlias(true);
  paint.setStyle(Paint.Style.STROKE);
  paint.setStrokeCap(Paint.Cap.ROUND);
  colors = new int[]{getColor(R.color.widget_album_ring_color1), getColor(R.color.widget_album_ring_color2),
    getColor(R.color.widget_album_ring_color1), getColor(R.color.widget_album_ring_color2),
    getColor(R.color.widget_album_ring_color1)};

  TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.WidgetAlbumBgView);
  ringWidth = (int) typedArray.getDimension(R.styleable.WidgetAlbumBgView_ring_width, getResources().getDimension(R.dimen.widget_album_ring_width));
  ringLineWidth = (int) typedArray.getDimension(R.styleable.WidgetAlbumBgView_ring_line_width, getResources().getDimension(R.dimen.widget_album_ring_line_width));
  typedArray.recycle();
 }

 @Override
 protected void onDraw(Canvas canvas) {
  super.onDraw(canvas);
  paint.setStrokeWidth(ringWidth);
  paint.setColor(getColor(R.color.widget_album_ring_color1));
  if (gradient == null) {
   gradient = new SweepGradient(getWidth() * 0.5F, getHeight() * 0.5F, colors, new float[]{
     0F, 0.25F, 0.5F, 0.75F, 1F
   });
  }
  paint.setShader(gradient);
  // 畫圓環(huán)
  canvas.drawCircle(getWidth() * 0.5F, getHeight() * 0.5F, (getWidth() - ringWidth) * 0.5F, paint);
  paint.setShader(null);
  paint.setStrokeWidth(ringLineWidth);
  paint.setColor(getColor(R.color.widget_album_ring_line_color));
  // 畫圓線
  for (int marginOut : ringLinesMarginOut) {
   canvas.drawCircle(getWidth() * 0.5F, getHeight() * 0.5F, getWidth() * 0.5F - marginOut - ringLineWidth * 0.5F, paint);
  }
 }

}

4.整體布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="@dimen/widget_album_size_vertical"
 android:layout_height="@dimen/widget_album_size_vertical"
 android:background="@drawable/rotate_album_bg">

 <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="true"
  android:scaleType="centerInside"
  android:src="@mipmap/ic_qifenle" />

 <com.example.musicalbumview.view.WidgetAlbumBgView
  android:layout_width="86.49dp"
  android:layout_height="86.49dp"
  android:layout_centerInParent="true" />
</RelativeLayout>

四.github地址

點擊鏈接

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android曲線更圓滑的簽名畫板

    Android曲線更圓滑的簽名畫板

    這篇文章主要為大家詳細介紹了Android曲線更圓滑的簽名畫板,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-04-04
  • android系統(tǒng)按鍵音framework流程源碼詳細解析

    android系統(tǒng)按鍵音framework流程源碼詳細解析

    這篇文章主要為大家詳細介紹了android系統(tǒng)按鍵音framework流程源碼,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-08-08
  • Android編程之TabWidget選項卡用法實例分析

    Android編程之TabWidget選項卡用法實例分析

    這篇文章主要介紹了Android編程之TabWidget選項卡用法,結(jié)合實例形式較為詳細的分析了TabWidget選項卡的具體實現(xiàn)技巧與使用注意事項,需要的朋友可以參考下
    2015-12-12
  • Android中通過外部程序啟動App的三種方法

    Android中通過外部程序啟動App的三種方法

    這篇文章主要介紹了Android中通過外部程序啟動App的三種方法,本文講解了直接通過包名、通過自定義的Action、通過Scheme三種方法,并分別給出操作代碼,需要的朋友可以參考下
    2015-04-04
  • Android編程簡單設(shè)置ListView分割線的方法

    Android編程簡單設(shè)置ListView分割線的方法

    這篇文章主要介紹了Android編程簡單設(shè)置ListView分割線的方法,涉及Android布局簡單操作技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2017-02-02
  • Android?實現(xiàn)自定義折線圖控件

    Android?實現(xiàn)自定義折線圖控件

    這篇文章主要介紹了Android?實現(xiàn)自定義折線圖控件,文章圍繞主題相關(guān)內(nèi)容展開詳細的內(nèi)容介紹,具有一定的參考價值,更興趣的小伙伴可以參考一下
    2022-06-06
  • Android仿qq消息拖拽效果

    Android仿qq消息拖拽效果

    這篇文章主要為大家詳細介紹了Android仿qq消息拖拽效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-01-01
  • 實例講解Android多線程應(yīng)用開發(fā)中Handler的使用

    實例講解Android多線程應(yīng)用開發(fā)中Handler的使用

    這篇文章主要介紹了Android多線程應(yīng)用開發(fā)中Handler的使用,Handle主要被用來更新UI和處理消息,需要的朋友可以參考下
    2016-01-01
  • Android編程獲取網(wǎng)址HTML代碼的方法

    Android編程獲取網(wǎng)址HTML代碼的方法

    這篇文章主要介紹了Android編程獲取網(wǎng)址HTML代碼的方法,涉及Android針對給定URL地址的網(wǎng)頁相關(guān)信息操作技巧,需要的朋友可以參考下
    2017-06-06
  • Android制作微信添加多個圖片放大圖片功能

    Android制作微信添加多個圖片放大圖片功能

    這篇文章主要介紹了Android制作微信添加多個圖片放大圖片功能,本文通過示例代碼給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友參考下吧
    2024-03-03

最新評論