Maybe somebody can give some light to build a listview in Android like Ultravisual APP.
I have implemented for IOS https://www.raywenderlich.com/99087/swift-expanding-cells-ios-collection-views, now I need to make similar work for Android.
I have this code, but If you implement this you will find a little issue when scrolling.
package com.ultravisualtest.ui;
import android.util.Log;
import android.view.View;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
public class HomeScrollListener implements OnScrollListener {
private float featuredHeight = 280f * android.content.res.Resources.getSystem().getDisplayMetrics().density;
private float standardHeight = 100f * android.content.res.Resources.getSystem().getDisplayMetrics().density;
private float dragOffset = 280f * android.content.res.Resources.getSystem().getDisplayMetrics().density;
private AbsListView _absListView;
private int _firstVisibleItem;
private int _visibleItemCount;
private int _totalItemCount;
private boolean userScrolled = false;
//pixels
public float getContentOffset(){
return Math.abs(_absListView.getChildAt(0).getTop());
}
public int getFeaturedItemIndex(){
return Math.max(0,(int)(getContentOffset()/dragOffset));
}
public float getNextItemPercentageOffset(){
return getContentOffset() / featuredHeight;
}
public float getWidth(){
return _absListView.getWidth();
}
public float getHeight(){
return _absListView.getHeight();
}
public int getNumberOfItems(){
return _visibleItemCount;
}
public HomeScrollListener(AbsListView list) {
}
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE) {
userScrolled = false;
} else if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_FLING ||
scrollState == AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
userScrolled = true;
}
}
@Override
public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if(userScrolled){
_absListView = absListView;
_firstVisibleItem = firstVisibleItem;
_visibleItemCount = visibleItemCount;
_totalItemCount = totalItemCount;
float y = 0;
for (int j = 0; j < visibleItemCount; j++) {
if (absListView.getChildAt(j).getClass() == FrameLayout.class) {
FrameLayout item = (FrameLayout) absListView.getChildAt(j);
if (item != null) {
RelativeLayout relative1 = (RelativeLayout) item.getChildAt(0);
View promoOverlay = (View) relative1.getChildAt(1);
float height = standardHeight;
promoOverlay.setAlpha(0.5f);
if (j == getFeaturedItemIndex()) {
height = featuredHeight;
float yOffset = standardHeight * getNextItemPercentageOffset();
y = getContentOffset() - yOffset;
promoOverlay.setAlpha(0);
} else if (j == getFeaturedItemIndex() + 1) {
float maxY = y + standardHeight;
height = standardHeight + Math.max((featuredHeight - standardHeight) * getNextItemPercentageOffset(), 0);
y = maxY - height;
promoOverlay.setAlpha(0.5f - getNextItemPercentageOffset()/2);
}
item.setLayoutParams(new AbsListView.LayoutParams((int)getWidth(), (int) height));
item.setTranslationY(y);
}
}
}
}
}
}
Somebody can help a little ??