The item gets larger when you move the ListView

I would like to implement the list effect in android as the one displayed in the Ultravisual Iphone app:

enter image description here

A similar effect can be viewing the Expo Milano 2015 application in android.

I would like the top element to become larger when populating the ListView.

I have no idea how this can be done ... Is this an animation of the first element in the current view?

If someone has an example or key to achieving this, it will be great!

thanks

+4
source share
1 answer

Well, I tried to achieve this effect, and it looked like this:

enter image description here

First you need to start determining the font size max and min. I have done this:

private final int MAX_FONTSIZE=50; private final int MIN_FONTSIZE=12; 

Then you need to keep the overall screen height. In your onCreate, save it like this:

  WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); Point size = new Point(); display.getSize(size); mScreenHeight = size.y; 

Then override the listview onScroll event and do the following:

  @Override public void onScroll(AbsListView view, int firstVisibleItem,int visibleItemCount, int totalItemCount) { if(listview.getChildCount()>0) for(int i=0;i<listview.getChildCount();i++) { float font = Math.min(Math.max(MAX_FONTSIZE - (float)(((MAX_FONTSIZE-MIN_FONTSIZE)/(mScreenHeight*0.3)))*Math.max(listview.getChildAt(i).getTop(),0),MIN_FONTSIZE),MAX_FONTSIZE); ((TextView)listview.getChildAt(i)).setTextSize(font); } } 

0.3 means that at about 30% of the screen there will always be a minimum font size. You can adjust this value to whatever you want. Remember that listview.getChildAt(i) will return the view that you are inflating on your adapter. In my case, this is just a text view, so it's safe to drop it in a TextView. You may need to call findViewById to get a text view.

You may also need to make the TextView in the center to make it look prettier.

EDIT

Since op wants to resize the view (which should not be used with this code), here is what hack you can do. Start by changing the min / max constants to what you want (100 and 250). Then go on to create a flag that controls whether the list scrolls or not. In your onScrollStateChanged add this line isScrolling= i == SCROLL_STATE_TOUCH_SCROLL || i == SCROLL_STATE_FLING; isScrolling= i == SCROLL_STATE_TOUCH_SCROLL || i == SCROLL_STATE_FLING; where i is the second onScrollStateChanged parameter. Then change the line to if(listview.getChildCount()>0 && isScrolling) . The next step is to change the height of the view. For this you need to change its layoutParams.

listview.getChildAt(i).setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, Math.round(font * getResources().getDisplayMetrics().density)));

Remember that this, as I said, is a simple hack. This is actually not the best solution. But since this is a difficult thing, let them stick to the basics.

+7
source

Source: https://habr.com/ru/post/1246926/


All Articles