DragLayout显示在屏幕三分之二的地方,往下拖,即可显示背后的View
import android.content.Context;
import android.graphics.Rect;
import android.support.v4.view.ViewCompat;
import android.support.v4.widget.ViewDragHelper;
import android.util.AttributeSet;
import android.view.*;
import android.widget.FrameLayout;
import com.hide.transitionstest.app.R;
public class DragLayout extends FrameLayout {
public static final int STATE_COLLAPSE = 1;
public static final int STATE_EXPAND = 2;
private ViewGroup mDragContent;
private View mTouchView;
private IDragListener iDragListener;
private ViewDragHelper mDragHelper;
private int mSlideMaxY;
private int mTopPadding;
private int mCurState = STATE_EXPAND;
private ViewDragHelper.Callback mCallback = new ViewDragHelper.Callback() {
@Override
public boolean tryCaptureView(View child, int pointerId) {
return child == mDragContent;
}
@Override
public int clampViewPositionVertical(View child, int top, int dy) {
return clampHeight(top);
}
@Override
public void onViewPositionChanged(View changedView, int left, int top, int dx, int dy) {
if (iDragListener != null) {
iDragListener.onDragChange(dragPercent(top));
}
}
@Override
public int getViewVerticalDragRange(View child) {
return mSlideMaxY;
}
@Override
public void onViewReleased(View releasedChild, float xvel, float yvel) {
super.onViewReleased(releasedChild, xvel, yvel);
int settleTop = mTopPadding;
int slideRange = releasedChild.getTop() - mTopPadding;
switch (mCurState) {
case STATE_EXPAND:
if (yvel >= 0
&& slideRange > mSlideMaxY / 5) {
settleTop = getHeight() - mTouchView.getMeasuredHeight();
}
break;
case STATE_COLLAPSE:
slideRange = getHeight() - releasedChild.getTop() - mTouchView.getMeasuredHeight();
if (yvel > 0
|| slideRange
drag_layout.xml
用法:
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.transitions.everywhere.TransitionManager;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.FrameLayout;
import android.widget.ImageView;
import com.hide.transitionplayer.lib.TransitionPlayer;
import com.hide.transitionstest.app.widget.DragLayout;
/**
* * * * * * * * * * * * * * * * * * * * * * *
* Created by zhaoyiding
* Date: 15/10/12
* * * * * * * * * * * * * * * * * * * * * * *
**/
public class DragTransitionActivity extends Activity
implements DragLayout.IDragListener {
private View mDimView;
private ViewGroup mSceneRoot;
private TransitionPlayer mTransitionPlayer = new TransitionPlayer();
private ImageView mHeadImg;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_drag_transition);
// mDimView = findViewById(R.id.dimView);
// mSceneRoot = (ViewGroup) findViewById(R.id.scene_root);
// mHeadImg = (ImageView) findViewById(R.id.headimg);
//
// initImg();
final DragLayout mDragLayout = (DragLayout) findViewById(R.id.drag_layout);
mDragLayout.setOnDragListener(this);
// mDragLayout.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
// @Override
// public boolean onPreDraw() {
// mDragLayout.getViewTreeObserver().removeOnPreDrawListener(this);
// TransitionManager.beginDelayedTransition(mSceneRoot, mTransitionPlayer);
// ViewGroup.MarginLayoutParams marginParams = (ViewGroup.MarginLayoutParams) mHeadImg.getLayoutParams();
// marginParams.topMargin = 0;
// mHeadImg.setLayoutParams(marginParams);
// mHeadImg.setAlpha(1.0f);
//
// mHeadImg.post(new Runnable() {
// @Override
// public void run() {
// mTransitionPlayer.setCurrentFraction(1.0f);
//
// }
// });
// return false;
// }
// });
}
// private void initImg() {
// int height = getResources().getDisplayMetrics().heightPixels / 3 - IndexActivity.sStatusBarHeight;
// FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, height);
// params.topMargin = -height * 2 / 3;
// mHeadImg.setLayoutParams(params);
// mHeadImg.setAlpha(0f);
// }
//
// private void setDimViewAlpha(float fraction) {
// mDimView.setBackgroundColor(Color.argb((int) (255 * fraction), 0, 0, 0));
// mTransitionPlayer.setCurrentFraction(fraction);
// }
@Override
public void onDragChange(float fraction) {
// setDimViewAlpha(fraction);
}
}
布局activity_drag_transition.xml:
仿豌豆荚ViewPager下拉:DragTopLayout
http://www.open-open.com/lib/view/open1422430262923.html
- 大小: 365.3 KB
- 查看图片附件
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
机房租用,北京机房租用,IDC机房托管, http://www.e1idc.net