Not all view of elements in LinearLayout



  • There's a cardView there's a linearLayout with six elements.

    <LinearLayout
                    android:orientation="vertical"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:id="@+id/CardDetail"
                    android:visibility="gone">
    
                &lt;View
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:layout_alignBottom="@+id/imageView"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true"
                    android:background="#e1e1e1"
                    android:layout_weight="1" /&gt;
    
                &lt;LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginLeft="5dp"
                    android:layout_marginRight="5dp"
                    android:gravity="center"
                    android:layout_marginTop="2dp"
                    android:id="@+id/edit"&gt;
    
                    &lt;TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Редактировать список"
                        android:id="@+id/textView"
                        android:layout_weight="1" /&gt;
    
                    &lt;ImageView
                        app:srcCompat="@drawable/icon_edit"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_vertical" /&gt;
                &lt;/LinearLayout&gt;
    
                &lt;LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginLeft="5dp"
                    android:layout_marginRight="5dp"
                    android:gravity="center"
                    android:id="@+id/remove"&gt;
    
                    &lt;TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Удалить список"
                        android:id="@+id/textView2"
                        android:layout_weight="1" /&gt;
    
                    &lt;ImageView
                        app:srcCompat="@drawable/icon_remove"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_vertical" /&gt;
    
                &lt;/LinearLayout&gt;
    
                &lt;LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginLeft="5dp"
                    android:layout_marginRight="5dp"
                    android:gravity="center"
                    android:id="@+id/upload"&gt;
    
                    &lt;TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Загрузить в центр загрузок"
                        android:id="@+id/textView3"
                        android:layout_weight="1" /&gt;
    
                    &lt;ImageView
                        app:srcCompat="@drawable/icon_upload"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_vertical" /&gt;
                &lt;/LinearLayout&gt;
    
                &lt;View
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:layout_alignBottom="@+id/imageView"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true"
                    android:background="#e1e1e1"
                    android:layout_marginTop="5dp" /&gt;
    
                &lt;android.support.v7.widget.RecyclerView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:id="@+id/recycler_view"
                    android:layout_below="@+id/toolbar"
                    android:layout_marginTop="5dp"
                    android:layout_marginRight="5dp"
                    android:layout_marginLeft="5dp"
                    android:layout_marginBottom="5dp" /&gt;
            &lt;/LinearLayout&gt;
    

    Initially, his visibility is gone, but when I press the button, I'm making LinearLayout Visible (View.Visible) and animating cardView, but instead of seeing all the elements, only one second element becomes visible.

    Here's animation code and height location.

    package ru.landmarkstd.educt.FunctionalClass;

    import android.support.v7.widget.CardView;
    import android.util.Log;
    import android.view.View;
    import android.view.ViewGroup;
    import android.view.animation.Animation;
    import android.view.animation.Transformation;

    import java.lang.reflect.Method;

    public class ExpandAndCollapce
    {
    public static void expand(CardView cardView,final ViewGroup v, int duration)
    {
    slide(cardView,v, duration, true);
    }

    public static void collapse(CardView cardView,final ViewGroup v, int duration)
    {
        slide(cardView,v, duration, false);
    }
    
    private static void slide(final CardView cardView, final ViewGroup v, int duration, final boolean expand)
    {
        try
        {
            Method m = v.getClass().getDeclaredMethod("onMeasure", int.class, int.class);
            m.setAccessible(true);
            m.invoke(
                    v,
                    View.MeasureSpec.makeMeasureSpec(((View) v.getParent()).getMeasuredWidth(), View.MeasureSpec.AT_MOST),
                    View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)
            );
        } catch (Exception e) {
            Log.e("slideAnimation", e.getMessage(), e);
        }
    
        final int initialHeight = v.getMeasuredHeight();
    
        if (expand)
        {
            v.getLayoutParams().height = 0;
        }
        else
        {
            v.getLayoutParams().height = initialHeight;
        }
        v.setVisibility(View.VISIBLE);
    
        Animation a = new Animation()
        {
            @Override
            protected void applyTransformation(float interpolatedTime, Transformation t)
            {
                int newHeight = 0;
                if (expand)
                {
                    newHeight = (int) (initialHeight * interpolatedTime);
                }
                else
                {
                    newHeight = (int) (initialHeight * (1 - interpolatedTime));
                }
                v.getLayoutParams().height = newHeight;
                v.requestLayout();
    
                if (interpolatedTime == 1 &amp;&amp; !expand)
                {
                    v.setVisibility(View.GONE);
                }
            }
    
            @Override
            public boolean willChangeBounds()
            {
                return true;
            }
        };
    
        a.setDuration(duration);
        v.startAnimation(a);
    }
    

    }

    It's a full cardView.

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    &lt;android.support.v7.widget.CardView
        android:id="@+id/card_view"
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="5dp"
        android:layout_marginBottom="5dp"
        card_view:cardElevation="4dp"
        card_view:cardUseCompatPadding="true"&gt;
    
        &lt;LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"&gt;
    
            &lt;LinearLayout
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:layout_marginBottom="5dp"&gt;
    
                &lt;LinearLayout
                    android:orientation="vertical"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:layout_marginLeft="5dp"&gt;
    
                    &lt;CheckBox
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:text="Название списка"
                        android:id="@+id/checkBox"
                        android:layout_weight="1"
                        android:theme="@style/MyCheckBox"
                        android:maxLines="1"
                        android:minLines="1" /&gt;
    
                    &lt;TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:id="@+id/textView4"
                        android:layout_marginLeft="5dp"
                        android:text="Арифметика" /&gt;
                &lt;/LinearLayout&gt;
    
                &lt;ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/open"
                    app:srcCompat="@drawable/icon_open_card"
                    android:layout_gravity="center_vertical"
                    android:clickable="true"
                    android:layout_marginRight="5dp" /&gt;
    
            &lt;/LinearLayout&gt;
    
            &lt;LinearLayout
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/CardDetail"
                android:visibility="gone"&gt;
    
                &lt;View
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:layout_alignBottom="@+id/imageView"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true"
                    android:background="#e1e1e1"
                    android:layout_weight="1" /&gt;
    
                &lt;LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginLeft="5dp"
                    android:layout_marginRight="5dp"
                    android:gravity="center"
                    android:layout_marginTop="2dp"
                    android:id="@+id/edit"&gt;
    
                    &lt;TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Редактировать список"
                        android:id="@+id/textView"
                        android:layout_weight="1" /&gt;
    
                    &lt;ImageView
                        app:srcCompat="@drawable/icon_edit"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_vertical" /&gt;
                &lt;/LinearLayout&gt;
    
                &lt;LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginLeft="5dp"
                    android:layout_marginRight="5dp"
                    android:gravity="center"
                    android:id="@+id/remove"&gt;
    
                    &lt;TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Удалить список"
                        android:id="@+id/textView2"
                        android:layout_weight="1" /&gt;
    
                    &lt;ImageView
                        app:srcCompat="@drawable/icon_remove"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_vertical" /&gt;
    
                &lt;/LinearLayout&gt;
    
                &lt;LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginLeft="5dp"
                    android:layout_marginRight="5dp"
                    android:gravity="center"
                    android:id="@+id/upload"&gt;
    
                    &lt;TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Загрузить в центр загрузок"
                        android:id="@+id/textView3"
                        android:layout_weight="1" /&gt;
    
                    &lt;ImageView
                        app:srcCompat="@drawable/icon_upload"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_vertical" /&gt;
                &lt;/LinearLayout&gt;
    
                &lt;View
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:layout_alignBottom="@+id/imageView"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true"
                    android:background="#e1e1e1"
                    android:layout_marginTop="5dp" /&gt;
    
                &lt;android.support.v7.widget.RecyclerView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:id="@+id/recycler_view"
                    android:layout_below="@+id/toolbar"
                    android:layout_marginTop="5dp"
                    android:layout_marginRight="5dp"
                    android:layout_marginLeft="5dp"
                    android:layout_marginBottom="5dp" /&gt;
            &lt;/LinearLayout&gt;
    
        &lt;/LinearLayout&gt;
    
    &lt;/android.support.v7.widget.CardView&gt;
    

    </LinearLayout>

    And this is animation code from the main activation.

    open = (ImageView) itemView.findViewById(R.id.open);
    cv = (CardView) itemView.findViewById(R.id.card_view);
    linearLayoutDetails = (LinearLayout) itemView.findViewById(R.id.CardDetail);

    holder.open.setOnClickListener(new View.OnClickListener()
    {
    @Override
    public void onClick(View v)
    {
    if (holder.linearLayoutDetails.getVisibility() == View.GONE)
    {
    ExpandAndCollapce.expand(holder.cv,holder.linearLayoutDetails, 500);

                    ObjectAnimator rotation = ObjectAnimator.ofFloat(v, "rotation", 180);
                    rotation.setDuration(500);
                    rotation.start();
                }
                else
                {
                    ExpandAndCollapce.collapse(holder.cv,holder.linearLayoutDetails, 500);
    
                    ObjectAnimator rotation = ObjectAnimator.ofFloat(v, "rotation", 0);
                    rotation.setDuration(500);
                    rotation.start();
                }
            }
        });
    



  • Everything was very simple, all elements in linear layout stood match_parent, with wrap_content, everything changed.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2