Я пытаюсь сделать паралакс эффект, и наконец я его вроде сделал, проблема в том что он работает для верхних элементов, а для нижних(чем ниже тем хуже) не работает. Вот код
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
//int lastTop = 0;
HashMap<Integer, Integer> lastBottom = new HashMap<Integer, Integer>();
int SIZE = 400;
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
//
int pos = view.getFirstVisiblePosition();
Log.e("what", "first visible position :" + pos + " visibleItemCount :" + visibleItemCount); // На нижних элементах это работает.
for(int i = pos; i < pos+visibleItemCount; i++){
View child = view.getChildAt(i);
if(child != null) {
int bottom = SIZE - child.getBottom();
if(lastBottom.get(i) == null){ lastBottom.put(i, 0); }
if (lastBottom.get(i) != bottom) {
TextView textView = (TextView) child.findViewById(R.id.textView);
ImageView imageView = (ImageView) child.findViewById(R.id.imageView);
textView.setText("bottom : " + bottom); // На нижних элементах текст не обновляется.
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) textView.getLayoutParams();
FrameLayout.LayoutParams params1 = (FrameLayout.LayoutParams) imageView.getLayoutParams();
params1.setMargins(0,0,0, -bottom / 10);
imageView.setLayoutParams(params1);
lastBottom.put(i, bottom);
}
}
}
}
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
});
Элементов 10, каждый элемент представляет собой такое
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="300px">
<ImageView
android:layout_width="match_parent"
android:layout_height="600px"
android:layout_gravity="bottom"
android:id="@+id/imageView" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="New Text"
android:layout_gravity="bottom"
android:textSize="30sp"
android:textColor="#fff"
android:paddingTop="30sp"
android:background="@drawable/gradient"
android:id="@+id/textView" />
</FrameLayout>