logo
down
shadow

ListView Animation not working on first/top 3-4 visible list items


ListView Animation not working on first/top 3-4 visible list items

By : sgeorgi
Date : November 17 2020, 04:28 AM
I wish did fix the issue. Finally i have solved it using [RecyclerView][1].
Now i don't have to invalidateViews() or reset the new MyAdapter(...).
code :


Share : facebook icon twitter icon
Animation does not start in ListView items that are currently visible

Animation does not start in ListView items that are currently visible


By : varun kumar
Date : March 29 2020, 07:55 AM
I wish this help you Tell adapter to animate views next time it will be asked for view. Call invalidateViews(). When getView is called on adapter create view and animate it.
Animating list items that are partially hidden or at the end of the currently visible views in a ListView

Animating list items that are partially hidden or at the end of the currently visible views in a ListView


By : reet
Date : March 29 2020, 07:55 AM
Any of those help To fix this issue I ended up adding a ACTION_MOVE case statement in my onTouch method. So as long as the list items were focused again, when the list performed a move i.e. scrolled the list item, the remaining list items are restored to their original size. To achieve this you need to maintain a map/collection of id's that correspond to your list items and iterate over them once the user scrolls.
Heres the full somwhat functiong implementation:
code :
package com.sun.tweetfiltrr.zoomlistview;
import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.ScaleAnimation;
import android.widget.AdapterView;
import android.widget.ListAdapter;
import android.widget.ListView;

import com.sun.tweetfiltrr.animation.CyclicFlipAnimation;

import java.util.HashMap;
import java.util.Map;

/**
 */
public class ZoomListView extends ListView implements AdapterView.OnItemLongClickListener {


    private static final String TAG = ZoomListView.class.getName();
    private int _xPos;
    private int _yPos;
    private int _pointerId;
    private Rect _viewBounds;
    private boolean _isZoomed;
    private OnItemClickListener _listner;
    private OnItemFocused _onItemFocusedLis;
    private int _expandingViewHeight = 0;
    private int _previousFocusedViewHeight;
    private OnScrollListener _onScrollListener;
    private boolean _shouldPerformScrollAnimation;
    final private Map<Long, PropertyHolder> _itemIDToProperty = new HashMap<Long, PropertyHolder>();
    private long _currentFocusedId;


    public interface OnItemFocused {

        /**
         * This interface can be used to be notified when a particular item should be disabled, or is currently not focused
         * @param position
         */
        public void onItemScaleOut(int position, View view, boolean status_);
        public void onItemRestore(int position, View view, boolean status_);
        public View onItemFocused(View focusedView_, int listViewPosition_, long uniqueId_);
    }

    public ZoomListView(Context context_) {
        super(context_);
        init(context_);
    }

    public ZoomListView(Context context_, AttributeSet attrs) {
        super(context_, attrs);
        init(context_);

    }

    public ZoomListView(Context context_, AttributeSet attrs, int defStyle) {
        super(context_, attrs, defStyle);
        init(context_);

    }


    private void init(Context context_){
        setOnItemLongClickListener(this);
    }

    public void setOnItemDisableListener(OnItemFocused listener_){
        _onItemFocusedLis = listener_;
    }

    private void scaleChildViews(long rowId_, int itemPos_, float scale, boolean shouldEnable){

        if (_isZoomed) {
            getParent().requestDisallowInterceptTouchEvent(true);
        }

        scaleAllVisibleViews(shouldEnable);
    }


    private void scaleAllVisibleViews(final boolean shouldEnable_) {
        final ListAdapter adapter = getAdapter();
        Animation scaleAnimation;
        if(_isZoomed){
            scaleAnimation = getZoomAnimation(1f, 0.6f, 1f, 0.6f);
        }else{
            scaleAnimation = getZoomAnimation(0.6f, 1f, 0.6f, 1f);
        }

        int count = getChildCount();
            for (int i = 0; i < count; i++) {
                applyAnimation(i, adapter, shouldEnable_, scaleAnimation);
            }
    }


    private void applyAnimation(int position_, ListAdapter adapter_, boolean shouldEnable_, Animation animation_){
        if (_isZoomed) {
                if (_currentFocusedId != adapter_.getItemId(position_)) {
                    scaleView(position_,  shouldEnable_, animation_);
                }else{
                    displayExpandingView(position_, adapter_);
                }
        }else{

            if(_currentFocusedId != getAdapter().getItemId(position_)){
                scaleView(position_,  shouldEnable_, animation_);
            }else{
                View view = getChildAt(position_);
                View viewToShow =  _onItemFocusedLis.onItemFocused(view, position_, getAdapter().getItemId(position_));

                if(viewToShow != null){
                    viewToShow.setVisibility(GONE);
                }
            }

            _itemIDToProperty.remove(getAdapter().getItemId(position_));
        }
    }

    private void displayExpandingView(int position_, ListAdapter adapter_){
        View view = getChildAt(position_);
        if(view != null){
            View viewToShow =  _onItemFocusedLis.onItemFocused(view, position_, adapter_.getItemId(position_));
            viewToShow.setVisibility(VISIBLE);
            Animation flip = new CyclicFlipAnimation(60f);
            flip.setDuration(1000);
            viewToShow.startAnimation(flip);

            if(_expandingViewHeight <= 0){
                viewToShow.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
                _expandingViewHeight = viewToShow.getMeasuredHeight();
            }

        }
    }

    private Animation getZoomAnimation(float fromX_, float toX_, float fromY_, float toY_){
      Animation  scaleAnimation = new ScaleAnimation(
                fromX_, toX_,
                fromY_, toY_,
                Animation.RELATIVE_TO_SELF, 0.5f,
                Animation.ABSOLUTE, 0.7f);
        scaleAnimation.setFillAfter(true);
        scaleAnimation.setDuration(500);
        return scaleAnimation;
    }

    private void scaleView(int position_,  boolean shouldEnable_, Animation animationScale_ ){
        View view = getChildAt(position_);
        ListAdapter adapter = getAdapter();
        long id = adapter.getItemId(position_);
        view.startAnimation(animationScale_);

        PropertyHolder holder = _itemIDToProperty.get(id);

        if (holder == null) {
            holder = new PropertyHolder((int) view.getTop(), (int) (view.getBottom()));
            _itemIDToProperty.put(id, holder);
        }

        int h = view.getHeight();
        if (_isZoomed) {
            view.animate().translationYBy((h * 0.5f)).setDuration(500).start();
            if (_onItemFocusedLis != null) {
                _onItemFocusedLis.onItemScaleOut(position_, view, shouldEnable_);
            }
        } else {
            view.animate().translationYBy(-(h * 0.5f )).setDuration(500).start();
            if (_onItemFocusedLis != null) {
                _onItemFocusedLis.onItemRestore(position_, view, shouldEnable_);
            }
        }

    }


    @Override
    public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
        _isZoomed = true;

        int firstVisiblePosition = getFirstVisiblePosition();
        int pos = pointToPosition(_xPos, _yPos);
        int positionOrg = pos - firstVisiblePosition;

        _currentFocusedId = getAdapter().getItemId(positionOrg);
        scaleChildViews(l, i, 0.8f, false);
        return true;
    }


    @Override
    public boolean onTouchEvent(MotionEvent event) {
        switch (event.getAction() & MotionEvent.ACTION_MASK) {
            case MotionEvent.ACTION_DOWN:
                _xPos = (int) event.getX();
                _yPos = (int) event.getY();
                _pointerId = event.getPointerId(0);

                if (_isZoomed) {
                    if (!_viewBounds.contains(_xPos, _yPos)) {
                        _isZoomed = false;
                        scaleChildViews(1, 1, 1f, true);
                    }
                    return false;
                }

                int position = pointToPosition(_xPos, _yPos);
                int childNum = (position != INVALID_POSITION) ? position - getFirstVisiblePosition() : -1;
                View itemView = (childNum >= 0) ? getChildAt(childNum) : null;
                if (itemView != null) {
                    _viewBounds = getChildViewRect(this, itemView);
                }

                break;

            case MotionEvent.ACTION_MOVE:
                if (!_isZoomed) {
                    animateRemaining();
                }
            break;
        }
        return super.onTouchEvent(event);
    }

    private void animateRemaining(){
        if(!_itemIDToProperty.isEmpty()){
        for(int i = 0; i < getChildCount(); i++){
           long id =  getAdapter().getItemId(i);
           PropertyHolder n = _itemIDToProperty.get(id);
            if(n != null){

                if(_currentFocusedId != getAdapter().getItemId(i)){
                    scaleView(i,  true, getZoomAnimation(0.6f, 1, 0.6f, 1f));
                }else{
                    Log.v(TAG, "not translating for " + getAdapter().getItemId(i)+ " for id " + _currentFocusedId);
                }
                _itemIDToProperty.remove(id);
            }
        }
        }
    }


    private Rect getChildViewRect(View parentView, View childView) {
        final Rect childRect = new Rect(childView.getLeft(), childView.getTop(), childView.getRight(), childView.getBottom() + _expandingViewHeight);
        if (parentView == childView) {
            return childRect;
        }

        ViewGroup parent = (ViewGroup) childView.getParent();
        while (parent != parentView) {
            childRect.offset(parent.getLeft(), parent.getTop());
            childView = parent;
            parent = (ViewGroup) childView.getParent();
        }
        return childRect;
    }

    private class PropertyHolder{
        int _top;
        int _bot;

        private PropertyHolder(int top_, int bot_){
            _top = top_;
            _bot = bot_;

        }

    }


}
Android ListView items animation - Animate only first visible items

Android ListView items animation - Animate only first visible items


By : Vijay Kumar
Date : March 29 2020, 07:55 AM
will be helpful for those in need Use the layout animation attribute in your xml
Docs here : http://developer.android.com/reference/android/view/ViewGroup.html#attr_android:layoutAnimation
code :
<?xml version="1.0" encoding="utf-8"?>
<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
        android:delay="0.5"
        android:animation="@anim/item_slide_in" />
<ListView
    android:id="@+id/foo"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layoutAnimation="@anim/layout_item_slide_in"" />
How to apply animation on the list items such that during an instance of time only one list item is visible?

How to apply animation on the list items such that during an instance of time only one list item is visible?


By : Aesha Patel
Date : November 17 2020, 11:01 PM
may help you . I just realized its for sure doable only with CSS, here is your code
https://jsfiddle.net/u6mno29m/1/
code :
 <div class="text_rotate">
    <ul>
      <li class="rotate">One</li>
      <li class="rotate">Two</li>
      <li class="rotate">Three</li>
    </ul>
  </div>
.rotate {
  position: absolute;
  top: 0px;
  opacity: 0;
  -moz-opacity: 0;
  filter:alpha(opacity=0);
}

.rotate:nth-child(1) {
  -webkit-animation: rotate 30s 0s infinite linear;
          animation: rotate 30s 0s infinite linear;
}

.rotate:nth-child(2) {
  -webkit-animation: rotate 30s 10s infinite linear;
          animation: rotate 30s 10s infinite linear;
}

.rotate:nth-child(3) {
  -webkit-animation: rotate 30s 20s infinite linear;
          animation: rotate 30s 20s infinite linear;
}

 @-webkit-keyframes "rotate" {
 0% {
   opacity: 0;
 }
 2% {
   opacity: 1;
 }
 31% {
   opacity: 1;
 }
 33% {
   opacity: 0;
 }
 100% {
   opacity: 0;
 }
}

 @keyframes "rotate" {
 0% {
   opacity: 0;
 }
 2% {
   opacity: 1;
 }
 31% {
   opacity: 1;
 }
 33% {
   opacity: 0;
 }
 100% {
   opacity: 0;
 }
}
Remove All items (visible and not visible) Custom listview Android?

Remove All items (visible and not visible) Custom listview Android?


By : Alan
Date : March 29 2020, 07:55 AM
should help you out If you want to remove all Item then just call clear() instead of remove(). Like this
Related Posts Related Posts :
  • Android Studio gradle build failed for hello world app
  • Slide a layout up from bottom of screen
  • Play HTML5 video in iOS/Android native media player
  • How to rescale a bitmap file in android?
  • No view found for id 0x for fragment after rotation?
  • Define different themable styles to the same widget types
  • ProGuard not working in my app
  • FragmentTransaction from BaseAdapter
  • Connecting multiple devices in a Wifi Direct group
  • Why TabActivity is deprecated in android
  • How to capture low resolution picture using android camera
  • android preferenceactivity padding in landscape orientation
  • How can I store cookie in webview?
  • Passing variables from one activity to another
  • Create Multicolored Pie Chart in Android Studio
  • how to kill progress dialog in android
  • Show Error on the tip of the Edit Text Android
  • How do I use getWindowManager() by another java file
  • fetching images from gallery on android phones with internal storage
  • How to discover devices like Google TV and Nexus-Q using MediaRoute API on Android?
  • "Unfortunately your app stopped working"- Facebook Integration for Android
  • How to animate button in android?
  • Resource Not Found Exception in class without context or activity
  • Launching Android Netflix App And Passing Video Id
  • Making a Phone Call with a Number Extension
  • NullPointerException at BoringLayout.isBoring is anything but boring
  • java.lang.RuntimeException: Unable to get provider
  • Testing custom Views with Robolectric
  • tools:listheader doesn't work although tools:listitem does
  • oppo, vivo app kill notification not coming in android fcm
  • OnClick Method could not function correctly with if else statement
  • Best method to download image from url in Android
  • How can I open Drawer Layout moving all the view and not just slide over?
  • how to show profile pictures of friends in a list view?
  • Creating TimePickerDialog with custom style in Android
  • Android 2.3.6 support library v7 option menu is missing
  • need of vblank in Display subssytem
  • Android MP4 stream - Video cannot be played
  • FastAdapter: Undo button does not show up after swipe
  • What are reasons to pass getActivity as the LifecycleOwner to the LiveData's observe method in a fragment?
  • Implement Face Recognition in Android
  • Titanium studio cannot run "titanium" command in terminal
  • How to execute command line ffmpeg commands programatically in android?
  • Make Android List Items clickable with each item pointing to a different link
  • listview runs successfully, but nothing is display in emulator
  • How to zoom in a bitmap with high resolution?
  • Passing listView data through intent
  • Google map route direction show by arrows in android v2
  • how to start "uiautomator test run" from android code?
  • Proguard in Android Library
  • Alarm Clock from GIT - Gives error - Android
  • Mock injection using Mockito - Android
  • Get Bitmap from universal image loader
  • Unable to include custom font in android
  • Basics on using logcat in Android development
  • Android: Clear cache programmatically
  • Android: pass object without serialization
  • Can not scroll and click item on gridview inside scrollview
  • Android device keeps disconnecting from adb / eclipse
  • Volley cannot create cache directory. Could not clean up file
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org