資源簡介
安卓的本地音樂播放器 可顯示歌詞,界面的切換使用了動畫效果,稍作修改可實現網易云的轉盤效果

代碼片段和文件信息
package?com.jiang.cn;
import?android.content.Context;
import?android.content.res.TypedArray;
import?android.util.AttributeSet;
import?android.view.View;
import?android.view.ViewConfiguration;
import?android.view.ViewGroup;
import?android.widget.ImageButton;
import?android.widget.Scroller;
/**
?*?自定義View,模仿android?桌面Luncher
?*/
public?class?BigDragableLuncher?extends?ViewGroup?{
//?按鈕背景色
int?choseColor?defaultColor;
//?底部按鈕數組
ImageButton[]?bottomBar;
//?負責得到滾動屬性的對象
private?Scroller?mScroller;
//?滾動的起始X坐標
private?int?mScrollX?=?0;
//?默認顯示第幾屏
private?int?mCurrentScreen?=?0;
public?int?mTouchSlop?=?0;
public?BigDragableLuncher(Context?context)?{
super(context);
mScroller?=?new?Scroller(context);
//?得到狀態位
mTouchSlop?=?ViewConfiguration.get(getContext()).getScaledTouchSlop();
//設置布局參數
this.setLayoutParams(new?ViewGroup.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT
ViewGroup.LayoutParams.FILL_PARENT));
}
public?BigDragableLuncher(Context?context?AttributeSet?attrs)?{
super(context?attrs);
mScroller?=?new?Scroller(context);
mTouchSlop?=?ViewConfiguration.get(getContext()).getScaledTouchSlop();
//設置布局參數
this.setLayoutParams(new?ViewGroup.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT
ViewGroup.LayoutParams.FILL_PARENT));
TypedArray?a?=?getContext().obtainstyledAttributes(attrs
R.styleable.DragableLuncher);
mCurrentScreen?=?a.getInteger(
R.styleable.DragableLuncher_default_screen?0);
}
//設置底部按鈕顏色
public?void?setBottomBarBg(ImageButton[]?ib?int?choseColor
int?defaultColor)?{
this.bottomBar?=?ib;
this.choseColor?=?choseColor;
this.defaultColor?=?defaultColor;
}
//屏幕滾動
public?void?snapToDestination()?{
final?int?screenWidth?=?getWidth();
//滑動距離超過1/2屏幕時,進入下一個界面
final?int?whichScreen?=?(mScrollX?+?(screenWidth?/?2))?/?screenWidth;
snapToScreen(whichScreen);
}
/**
?*?帶動畫效果顯示界面
?*/
public?void?snapToScreen(int?whichScreen)?{
mCurrentScreen?=?whichScreen;
final?int?newX?=?whichScreen?*?getWidth();
final?int?delta?=?newX?-?mScrollX;
mScroller.startScroll(mScrollX?0?delta?0?Math.abs(delta)?*?2);
invalidate();
}
/**
?*?不帶動畫效果顯示界面
?*/
public?void?setToScreen(int?whichScreen)?{
mCurrentScreen?=?whichScreen;
final?int?newX?=?whichScreen?*?getWidth();
mScroller.startScroll(newX?0?0?0?10);
invalidate();
}
//取得當前屏幕位置
public?int?getCurrentScreen()?{
return?mCurrentScreen;
}
//改變布局時調用
@Override
protected?void?onLayout(boolean?changed?int?l?int?t?int?r?int?b)?{
int?childLeft?=?0;
final?int?count?=?getChildCount();
for?(int?i?=?0;?i? final?View?child?=?getChildAt(i);
//從左到右依次排列子元素
if?(child.getVisibility()?!=?View.GONE)?{
final?int?childWidth?=?child.getMeasuredWidth();
child.layout(childLeft?0?childLeft?+?childWidth
child.getMeasuredHeight());
childLeft?+=?ch
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????????352??2018-06-28?13:07??MyMusicPla
?????目錄???????????0??2018-06-28?12:23??MyMusicPla
?????目錄???????????0??2018-06-28?13:11??MyMusicPla
?????文件???????54708??2018-06-28?12:23??MyMusicPla
?????文件?????????232??2018-06-28?13:11??MyMusicPla
?????文件????????5296??2018-06-28?12:23??MyMusicPla
?????文件????????2260??2018-06-28?12:23??MyMusicPla
?????文件????????1274??2018-06-28?12:23??MyMusicPla
?????目錄???????????0??2018-06-28?13:15??MyMusicPla
?????文件?????????592??2018-06-28?13:15??MyMusicPla
?????目錄???????????0??2018-06-28?12:23??MyMusicPla
?????目錄???????????0??2018-06-28?12:23??MyMusicPla
?????文件????????1430??2018-06-28?12:23??MyMusicPla
?????目錄???????????0??2018-06-28?12:23??MyMusicPla
?????目錄???????????0??2018-06-28?12:23??MyMusicPla
?????目錄???????????0??2018-06-28?12:23??MyMusicPla
?????目錄???????????0??2018-06-28?13:59??MyMusicPla
?????文件????????4310??2018-06-28?12:23??MyMusicPla
?????文件???????14793??2018-06-28?12:23??MyMusicPla
?????文件????????8824??2018-06-28?12:23??MyMusicPla
?????文件?????????617??2018-06-28?12:23??MyMusicPla
?????文件????????3194??2018-06-28?12:23??MyMusicPla
?????文件????????3668??2018-06-28?13:21??MyMusicPla
?????文件?????????597??2018-06-28?12:23??MyMusicPla
?????文件???????25247??2018-06-28?13:59??MyMusicPla
?????文件????????2749??2018-06-28?12:23??MyMusicPla
?????文件????????7375??2018-06-28?13:59??MyMusicPla
?????文件????????1592??2018-06-28?12:23??MyMusicPla
?????目錄???????????0??2018-06-28?12:23??MyMusicPla
?????目錄???????????0??2018-06-28?12:23??MyMusicPla
?????文件?????????280??2018-06-28?12:23??MyMusicPla
............此處省略87個文件信息
評論
共有 條評論