안 드 로 이 드 는 위 챗 모멘트 를 모방 하여 스크롤 바 드 롭 다운 바 운 드 효 과 를 실현 합 니 다.
1.효과 도
이 휴대 전 화 는 해상도 가 제한 되 어 있어 오래된 휴대 전화 디 버 깅 이다.
2、바 운 드 효과 가 있 음 BounceScrollView
package com.org.scroll;
import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.TranslateAnimation;
import android.widget.ScrollView;
/**
* ScrollView
*/
public class BounceScrollView extends ScrollView {
private View inner;// View
private float y;// y
// ( , .)
private Rect normal = new Rect();
private boolean isCount = false;//
public BounceScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
}
/***
* XML . , . onFinishInflate
* , , .
*/
@Override
protected void onFinishInflate() {
if (getChildCount() > 0) {
inner = getChildAt(0);
}
}
/***
* touch
*/
@Override
public boolean onTouchEvent(MotionEvent ev) {
if (inner != null) {
commOnTouchEvent(ev);
}
return super.onTouchEvent(ev);
}
/***
*
*
* @param ev
*/
public void commOnTouchEvent(MotionEvent ev) {
int action = ev.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
break;
case MotionEvent.ACTION_UP:
// .
if (isNeedAnimation()) {
animation();
isCount = false;
}
break;
/***
* , y , MotionEvent.ACTION_DOWN ,
* MyScrollView touch LIstView item . .
* , 0. .
*/
case MotionEvent.ACTION_MOVE:
final float preY = y;// y
float nowY = ev.getY();// y
int deltaY = (int) (preY - nowY);//
if (!isCount) {
deltaY = 0; // 0.
}
y = nowY;
// ,
if (isNeedMove()) {
//
if (normal.isEmpty()) {
//
normal.set(inner.getLeft(), inner.getTop(),
inner.getRight(), inner.getBottom());
}
// Log.e("jj", " :" + inner.getLeft() + "," + inner.getTop()
// + "," + inner.getRight() + "," + inner.getBottom());
//
inner.layout(inner.getLeft(), inner.getTop() - deltaY / 2,
inner.getRight(), inner.getBottom() - deltaY / 2);
}
isCount = true;
break;
default:
break;
}
}
/***
*
*/
public void animation() {
//
TranslateAnimation ta = new TranslateAnimation(0, 0, inner.getTop(),
normal.top);
ta.setDuration(200);
inner.startAnimation(ta);
//
inner.layout(normal.left, normal.top, normal.right, normal.bottom);
// Log.e("jj", " :" + normal.left + "," + normal.top + "," + normal.right
// + "," + normal.bottom);
normal.setEmpty();
}
//
public boolean isNeedAnimation() {
return !normal.isEmpty();
}
/***
* inner.getMeasuredHeight():
*
* getHeight():
*
* @return
*/
public boolean isNeedMove() {
int offset = inner.getMeasuredHeight() - getHeight();
int scrollY = getScrollY();
// Log.e("jj", "scrolly=" + scrollY);
// 0 ,
if (scrollY == 0 || scrollY == offset) {
return true;
}
return false;
}
}
3、MainActivity
package com.org.activity;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.Window;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
이것 은 아무것도 하지 않 았 습 니 다.주로 레이아웃 과 BounceScrollView 류 를 봅 니 다.4、activity_기본 레이아웃
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<include layout="@layout/common_title_bg" />
<com.org.scroll.BounceScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/coversation_bg"
android:focusable="true"
android:focusableInTouchMode="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="10.0dip" >
<RelativeLayout
android:id="@+id/accountSetting"
android:layout_width="fill_parent"
android:layout_height="63.0dip"
android:background="#80ffffff"
android:focusable="true" >
<FrameLayout
android:id="@+id/frameLayout1"
android:layout_width="54.0dip"
android:layout_height="54.0dip"
android:layout_centerVertical="true"
android:layout_marginLeft="10.0dip" >
<ImageView
android:id="@+id/face"
android:layout_width="50.0dip"
android:layout_height="50.0dip"
android:layout_gravity="center"
android:contentDescription="@null"
android:src="@drawable/h0" />
<ImageView
android:id="@+id/statusIcon"
android:layout_width="18.0dip"
android:layout_height="18.0dip"
android:layout_gravity="bottom|right|center"
android:contentDescription="@null" />
</FrameLayout>
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="10.0dip"
android:contentDescription="@null"
android:duplicateParentState="true" />
<TextView
android:id="@+id/status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/nick"
android:layout_marginRight="10.0dip"
android:layout_toLeftOf="@id/imageView1"
android:duplicateParentState="true"
android:text=" " />
<TextView
android:id="@+id/nick"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10.0dip"
android:layout_marginRight="69.0dip"
android:layout_toRightOf="@id/frameLayout1"
android:duplicateParentState="true"
android:ellipsize="end"
android:singleLine="true" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="600dp"
android:layout_marginTop="16.0dip"
android:layout_weight="2.13"
android:background="#ffffffff"
android:orientation="vertical" >
<TextView
android:id="@+id/my_profile"
android:layout_width="fill_parent"
android:layout_height="44.0dip"
android:background="#800000ff"
android:clickable="true"
android:gravity="center_vertical"
android:paddingLeft="10.0dip"
android:paddingRight="10.0dip"
android:text=" " />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16.0dip"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/set_feedback"
android:layout_width="fill_parent"
android:layout_height="44.0dip"
android:background="#8000ffff"
android:clickable="true"
android:focusable="true" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="12.0dip"
android:duplicateParentState="true"
android:gravity="center_vertical"
android:text=" " />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</com.org.scroll.BounceScrollView>
</LinearLayout>
원본 다운로드:Android 스크롤 바 드 롭 다운 바 운 드 효과 구현본 고 는 여러분 들 이 안 드 로 이 드 소프트웨어 프로 그래 밍 을 배 우 는 데 도움 이 되 기 를 바 랍 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Bitrise에서 배포 어플리케이션 설정 테스트하기이 글은 Bitrise 광고 달력의 23일째 글입니다. 자체 또는 당사 등에서 Bitrise 구축 서비스를 사용합니다. 그나저나 며칠 전 Bitrise User Group Meetup #3에서 아래 슬라이드를 발표했...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.