안 드 로 이 드 모방 경 동 금융 홈 페이지 프로필 효과
효과 도 를 보 니 gif 가 약간 끊 겨 서 실제 기기 에서 운행 효과 가 좋 습 니 다.
2.실현
재 미 있 는 효과 입 니 다.원 리 는 간단 합 니 다.바로 ScrollView 를 통 해 Y 축의 미끄럼 거 리 를 감청 한 다음 에 코드 에서 이미지 의 위치 와 크기 를 동적 으로 설정 하 는 것 입 니 다.
public class MainActivity extends AppCompatActivity {
private CircleImageView ivPortrait;
private ObservableScrollView scrollView;
private ViewGroup.MarginLayoutParams marginLayoutParams;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
}
private void initView() {
ivPortrait = (CircleImageView) findViewById(R.id.iv_portrait);
scrollView = (ObservableScrollView) findViewById(R.id.scrollView);
marginLayoutParams = new ViewGroup.MarginLayoutParams(ivPortrait.getLayoutParams());
scrollView.setScrollViewListener(new ObservableScrollView.ScrollViewListener() {
@Override
public void onScrollChanged(ObservableScrollView scrollView, int x, int y, int oldx, int oldy) {
//
int top = dp2px(70) - y;
if (top < dp2px(10)) {
//
marginLayoutParams.setMargins(dp2px(20), dp2px(10), 0, 0);
} else {
//
marginLayoutParams.setMargins(dp2px(20), dp2px(70) - y, 0, 0);
}
//
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(marginLayoutParams);
// 45dp, 30dp
int height = dp2px(45) - y < dp2px(30) ? dp2px(30) : dp2px(45) - y;
layoutParams.height = height;
layoutParams.width = height;
ivPortrait.setLayoutParams(layoutParams);
}
});
}
private int dp2px(float dp) {
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp,
getResources().getDisplayMetrics());
}
}
레이아웃 파일
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFF">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#F2F4F7">
...
</RelativeLayout>
<com.yl.jdfinanceindex.ObservableScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:overScrollMode="never"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="80dp"
android:background="#F2F4F7">
...
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1000dp" />
</LinearLayout>
</com.yl.jdfinanceindex.ObservableScrollView>
</LinearLayout>
<com.yl.jdfinanceindex.CircleImageView
android:id="@+id/iv_portrait"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="70dp"
android:src="@mipmap/ic_portrait" />
</FrameLayout>
원생 ScrollView 는 미끄럼 감청 이 지원 되 지 않 으 므 로 Observable ScrollView 를 사용자 정의 해 야 합 니 다.
public class ObservableScrollView extends ScrollView {
private ScrollViewListener scrollViewListener;
public ObservableScrollView(Context context) {
super(context);
}
public ObservableScrollView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public ObservableScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public void setScrollViewListener(ScrollViewListener scrollViewListener) {
this.scrollViewListener = scrollViewListener;
}
@Override
protected void onScrollChanged(int x, int y, int oldx, int oldy) {
super.onScrollChanged(x, y, oldx, oldy);
if (scrollViewListener != null) {
scrollViewListener.onScrollChanged(this, x, y, oldx, oldy);
}
}
public interface ScrollViewListener {
void onScrollChanged(ObservableScrollView scrollView, int x, int y, int oldx, int oldy);
}
}
3.마지막 에 쓴다학우 들 이 평론 하 는 것 을 환영 합 니 다.만약 당신 이 이 블 로그 가 당신 에 게 유용 하 다 고 생각한다 면,메 시 지 를 남기 거나 대 들 어 보 세 요.
온전한
이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 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에 따라 라이센스가 부여됩니다.