안 드 로 이 드 슬라이딩 최적화 QQ 6.0 사 이 드 슬라이더 메뉴(슬라이딩 최적화)
하지만 이전 에는 간단하게 왼쪽 메뉴 를 표시 하고 숨 길 수 있 었 지만 너무 딱딱 하고 매 끄 러 운 트 렌 드 가 없 었 습 니 다.오늘 은 부 드 러 운 효 과 를 더 해 제스처 가 미 끄 러 지 는 방향 에 따라 표시 와 숨 김 여 부 를 판단 할 수 있 습 니 다.
우선 제스처 를 해서 숨 기 고 표시 할 지 여 부 를 판단 하 겠 습 니 다.
여기에 한 가지 방법 이 필요 합 니 다.다음 과 같 습 니 다.
이것 은 View DradHelper 의 방법 입 니 다.
/**
* view ( )
*
* @param releasedChild view
* @param xvel +
* @param yvel +
*/
@Override
public void onViewReleased(View releasedChild, float xvel, float yvel) {
Log.d("DragLayout", "xvel : " + xvel + " yvel :" + yvel);
super.onViewReleased(releasedChild, xvel, yvel);
//
// ,
// mRange/2 0,
if (xvel >= 0 && mMainContent.getLeft() > mRange / 2.0f) {
open();
} else if (xvel > 0) {
// 0( , )
open();
} else {
//
close();
}
}
close()방법(DragLayout 안의 방법):
/**
*
*/
public void close() {
int finalLeft = 0;
// layout ,
/**
* @param l Left position, relative to parent
* @param t Top position, relative to parent
* @param r Right position, relative to parent
* @param b Bottom position, relative to parent
*/
mMainContent.layout(finalLeft, 0, finalLeft + mWidth, finalLeft + mHeight);
}
open()방법(DragLayout 안의 방법):
/**
*
*/
public void open() {
int finalLeft = mRange;
mMainContent.layout(finalLeft, 0, finalLeft + mWidth, finalLeft + mHeight);
}
이것 이 열 리 고 닫 혔 는 지 손짓 에 따라 판단 할 수 있 습 니까?그 다음 에 우 리 는 어떻게 부 드 럽 게 닫 고 열 수 있 는 지 를 실현 합 니 다.말 을 많이 하지 않 고 코드 를 말 합 니 다.(여기 서 위의 open 과 close 에 대해 처리 합 니 다)
public void close() {
close(true);
}
/**
*
*
* @param isSmooth
*/
public void close(boolean isSmooth) {
int finalLeft = 0;
if (isSmooth) {
/**
* public boolean smoothSlideViewTo(View child, int finalLeft, int finalTop)
*
* Animate the view <code>child</code> to the given (left, top) position.
* If this method returns true, the caller should invoke {@link #continueSettling(boolean)}
* on each subsequent frame to continue the motion until it returns false. If this method
* returns false there is no further work to do to complete the movement.
*
* true , ,
* false
*/
//1、
if (mDragHelper.smoothSlideViewTo(mMainContent, finalLeft, 0)) {
// this, child viewgroup
ViewCompat.postInvalidateOnAnimation(this);
}
} else {
// layout ,
/**
* @param l Left position, relative to parent
* @param t Top position, relative to parent
* @param r Right position, relative to parent
* @param b Bottom position, relative to parent
*/
mMainContent.layout(finalLeft, 0, finalLeft + mWidth, finalLeft + mHeight);
}
}
/**
*
*/
public void open(boolean isSmooth) {
int finalLeft = mRange;
if (isSmooth && mDragHelper.smoothSlideViewTo(mMainContent, finalLeft, 0)) {
// this, child viewgroup
ViewCompat.postInvalidateOnAnimation(this);
} else {
mMainContent.layout(finalLeft, 0, finalLeft + mWidth, finalLeft + mHeight);
}
}
public void open() {
open(true);
}
효과 도 를 살 펴 보 자.이 럴 때 는 거의 차이 가 나 지 않 습 니 다.나머지 는 상태 와 listener 를 설정 하 는 방법 을 추가 하여 밖의 호출 에 남 겨 두 겠 습 니 다.코드 는 간단 합 니 다:
/**
*
*/
private Status mStatus = Status.CLOSE;
/**
*
* CLOSE
* OPEN
* DRAGING
*/
public enum Status {
CLOSE, OPEN, DRAGING;
}
private OnDragStatusListener mListener;
public void setDragStateListener(OnDragStatusListener listener) {
mListener = listener;
}
public interface OnDragStatusListener {
/**
*
*/
void onClose();
/**
*
*/
void onOpen();
/**
*
*
* @param percent
*/
void onDraging(float percent);
}
상태 업데이트,방법 호출,이 dispatchDragEvent()는 onView Position Changed()이 방법 에서 호출 하면 됩 니 다.끌 때 상태 가 항상 변 하기 때문에 이 방법 에서 호출 합 니 다.
/**
*
*
* @param newLeft
*/
private void dispatchDragEvent(int newLeft) {
//
float percent = newLeft * 1.0f / mRange;
//0.0f--->1.0f
Log.d("DragLayout", "percent : " + percent);
if (mListener != null) {
mListener.onDraging(percent);
}
//
Status lastStatus = mStatus;
mStatus = updateStatus(percent);
if (mStatus != lastStatus) {
//
if (mStatus == Status.CLOSE) {
//
if (mListener != null) {
mListener.onClose();
}
} else if (mStatus == Status.OPEN) {
if (mListener != null) {
mListener.onOpen();
}
}
}
}
/**
*
*
* @param percent
* @return
*/
private Status updateStatus(float percent) {
if (percent == 0) {
return Status.CLOSE;
} else if (percent == 1) {
return Status.OPEN;
}
return Status.DRAGING;
}
자,이제 그만 QQ 6.0 사 이 드 스 케 이 트 가 거의 완성 되 었 습 니 다.다음은 효 과 를 살 펴 보 겠 습 니 다.자,이 사 이 드 스 케 이 트 는 이렇게 완성 되 었 습 니 다.나중에 홈 페이지 에 listview(Recycle View 로 시도)를 추가 하여 왼쪽 스 케 이 트 삭제 효 과 를 실현 합 니 다.현재 이 demo 의 주 소 를 첨부 하고 후기 에 추 가 된 것 도 여기에 업 데 이 트 됩 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Kotlin의 기초 - 2부지난 글에서는 Kotlin이 무엇인지, Kotlin의 특징, Kotlin에서 변수 및 데이터 유형을 선언하는 방법과 같은 Kotlin의 기본 개념에 대해 배웠습니다. 유형 변환은 데이터 변수의 한 유형을 다른 데이터...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.