This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<set xmlns:android="http://schemas.android.com/apk/res/android" | |
android:fillAfter="true" | |
android:zAdjustment="normal" > | |
<translate | |
android:duration="100" //100毫秒 | |
android:fromXDelta="0" //初始X | |
android:fromYDelta="0" //初始Y | |
android:toXDelta="100" //結束位置X | |
android:toYDelta="100" //結束位置Y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
velocityTracker.computeCurrentVelocity(1000); | |
int xVelocity = (int) velocityTracker.getXVelocity(); | |
int yVelocity = (int) velocityTracker.getYVelocity(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
VelocityTracker velocityTracker = VelocityTracker.obtain(); | |
velocityTracker.addMovement(event); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ViewConfiguration.get(getContext()).getScaledTouchSlop(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ObjectAnimator.ofFloat(targetView, "translationX", 0, 100).setDuration(100).start(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ObjectAnimator.ofFloat(targetView,"translationX",0,100).setDuration(100).start(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void scrollTo(int x,int y) { | |
if (mScrollX != x || mScrollY != y) { | |
int oldX = mScrollX; | |
int oldY = mScrollY; | |
mScrollX = x; | |
mScrollY = y; | |
invalidateParentCaches(); | |
onScrollChanged(mScrollX,mScrollY,oldX,oldY); | |
if (!awakenScrollBars()) { | |
postInvalidateOnAnimation(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//創建Scroller | |
Scroller scroller = new Scroller(mContext); | |
// 自訂的方法,緩慢滾動到指定位置 | |
private void smoothScrollTo(int destX,int destY, int time) { | |
int scrollX = getScrollX(); | |
int deltaX = destX -scrollX; | |
// 1000ms內滑向destX,效果就是慢慢滑動 | |
mScroller.startScroll(scrollX, 0, deltaX, 0, time); | |
invalidate(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//自訂的方法,緩慢滾動到指定位置 | |
private void smoothScrollTo(int destX, int destY, int time) { | |
int scrollX = getScrollX(); | |
int deltaX = destX - scrollX; | |
// 1000ms內滑向destX,效果就是慢慢滑動 | |
mScroller.startScroll(scrollX, 0, deltaX, 0, time); | |
invalidate(); | |
} | |
//計算一段時間間隔內偏移的距離,並返回是否滾動結束的標記 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity : AppCompatActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
findViewById(R.id.btIntentService).setOnClickListener{ | |
//啟動IntentService | |
startService(new Intent(MainActivity.this, MyIntentService.class)) | |
} | |
} |