下面列出了android.widget.FrameLayout#getLeft ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void onRelease(float eventX, float velocityX) {
animatingView = (FrameLayout) getChildAt(3);
animateValue = animatingView.getLeft();
int tag = Integer.parseInt(animatingView.getTag().toString());
// 计算目标位置
int destX = originX.get(3);
if (velocityX > VELOCITY_THRESHOLD || (animatingView.getLeft() > originX.get(3) + scrollDistanceMax / 2 && velocityX > -VELOCITY_THRESHOLD)) {
destX = originX.get(4);
tag--;
}
if (tag < 0 || tag >= adapter.getItemCount()) {
return;
}
if (Math.abs(animatingView.getLeft() - destX) < mTouchSlop && Math.abs(eventX - downX) < mTouchSlop) {
return;
}
adapter.displaying(tag);
animator = ObjectAnimator.ofFloat(this, "animateValue", animatingView.getLeft(), destX);
animator.setInterpolator(interpolator);
animator.setDuration(360).start();
}
private void onRelease(float eventX, int velocityX) {
animatingView = (FrameLayout) getChildAt(3);
animateValue = animatingView.getLeft();
int tag = Integer.parseInt(animatingView.getTag().toString());
// 计算目标位置
int destX = originX.get(3);
boolean isOrigin = animatingView.getLeft() > originX.get(3) + scrollDistanceMax / 2;
if (velocityX > VELOCITY_THRESHOLD || (isOrigin && velocityX > -VELOCITY_THRESHOLD)) {
destX = originX.get(4);
tag--;
}
if (tag < 0 || tag >= adapter.getItemCount()) {
return;
}
if (Math.abs(animatingView.getLeft() - destX) < mTouchSlop && Math.abs(eventX - downX) < mTouchSlop) {
return;
}
adapter.displaying(tag);
animator = ObjectAnimator.ofFloat(this, "animateValue", animatingView.getLeft(), destX);
animator.setInterpolator(interpolator);
animator.setDuration(360).start();
}
/***
* Hide the searchbox using the circle animation. Can be called regardless of result list length
* @param activity Activity
*/
public void hideCircularly(Activity activity){
Display display = activity.getWindowManager().getDefaultDisplay();
Point size = new Point();
final FrameLayout layout = (FrameLayout) activity.getWindow().getDecorView()
.findViewById(android.R.id.content);
RelativeLayout root = (RelativeLayout) findViewById(R.id.search_root);
display.getSize(size);
Resources r = getResources();
float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 96,
r.getDisplayMetrics());
int cx = layout.getLeft() + layout.getRight();
int cy = layout.getTop();
int finalRadius = (int) Math.max(layout.getWidth()*1.5, px);
SupportAnimator animator = ViewAnimationUtils.createCircularReveal(
root, cx, cy, 0, finalRadius);
animator.setInterpolator(new ReverseInterpolator());
animator.setDuration(250);
animator.start();
animator.addListener(new SupportAnimator.AnimatorListener(){
@Override
public void onAnimationStart() {
}
@Override
public void onAnimationEnd() {
setVisibility(View.GONE);
}
@Override
public void onAnimationCancel() {
}
@Override
public void onAnimationRepeat() {
}
});
}
private void revealFrom(float x, float y, Activity a, SearchBox s) {
FrameLayout layout = (FrameLayout) a.getWindow().getDecorView()
.findViewById(android.R.id.content);
RelativeLayout root = (RelativeLayout) s.findViewById(R.id.search_root);
Resources r = getResources();
float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 96,
r.getDisplayMetrics());
int cx = layout.getLeft() + layout.getRight();
int cy = layout.getTop();
int finalRadius = (int) Math.max(layout.getWidth(), px);
SupportAnimator animator = ViewAnimationUtils.createCircularReveal(
root, cx, cy, 0, finalRadius);
animator.setInterpolator(new AccelerateDecelerateInterpolator());
animator.setDuration(500);
animator.addListener(new SupportAnimator.AnimatorListener(){
@Override
public void onAnimationCancel() {
}
@Override
public void onAnimationEnd() {
toggleSearch();
}
@Override
public void onAnimationRepeat() {
}
@Override
public void onAnimationStart() {
}
});
animator.start();
}
/***
* Hide the searchbox using the circle animation. Can be called regardless of result list length
* @param activity
*/
public void hideCircularly(Activity activity){
Display display = activity.getWindowManager().getDefaultDisplay();
Point size = new Point();
final FrameLayout layout = (FrameLayout) activity.getWindow().getDecorView()
.findViewById(android.R.id.content);
RelativeLayout root = (RelativeLayout) findViewById(R.id.search_root);
display.getSize(size);
Resources r = getResources();
float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 96,
r.getDisplayMetrics());
int cx = layout.getLeft() + layout.getRight();
int cy = layout.getTop();
int finalRadius = (int) Math.max(layout.getWidth()*1.5, px);
SupportAnimator animator = ViewAnimationUtils.createCircularReveal(
root, cx, cy, 0, finalRadius);
animator.setInterpolator(new ReverseInterpolator());
animator.setDuration(500);
animator.start();
animator.addListener(new SupportAnimator.AnimatorListener(){
@Override
public void onAnimationStart() {
}
@Override
public void onAnimationEnd() {
setVisibility(View.GONE);
}
@Override
public void onAnimationCancel() {
}
@Override
public void onAnimationRepeat() {
}
});
}
private void revealFrom(float x, float y, Activity a, SearchBox s) {
Display display = a.getWindowManager().getDefaultDisplay();
Point size = new Point();
FrameLayout layout = (FrameLayout) a.getWindow().getDecorView()
.findViewById(android.R.id.content);
RelativeLayout root = (RelativeLayout) s.findViewById(R.id.search_root);
display.getSize(size);
Resources r = getResources();
float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 96,
r.getDisplayMetrics());
int cx = layout.getLeft() + layout.getRight();
int cy = layout.getTop();
int finalRadius = (int) Math.max(layout.getWidth(), px);
SupportAnimator animator = ViewAnimationUtils.createCircularReveal(
root, cx, cy, 0, finalRadius);
animator.setInterpolator(new AccelerateDecelerateInterpolator());
animator.setDuration(500);
animator.addListener(new SupportAnimator.AnimatorListener(){
@Override
public void onAnimationCancel() {
}
@Override
public void onAnimationEnd() {
toggleSearch();
}
@Override
public void onAnimationRepeat() {
}
@Override
public void onAnimationStart() {
}
});
animator.start();
}