Ошибка направления анимации сворачивания нижнего диалогового окна Android - PullRequest
1 голос
/ 20 марта 2019

Я использую пользовательское нижнее диалоговое окно, просто диалоговое окно, прикрепленное к нижней части экрана

вот код

https://github.com/javiersantos/BottomDialogs/blob/master/library/src/main/java/com/github/javiersantos/bottomdialogs/BottomDialog.java

Моя проблема - , когда я анимирую представление в этом диалоговом окне (сворачивание / развертывание), в нижней части экрана возникает черный разрыв, я просто хочу, чтобы нижняя часть диалогового окна была зафиксирована и только верхняя часть изменение диалога.

Вот видео. https://youtu.be/bU3elAE-eBU

Я пробовал с разными анимациями, но получил тот же результат.

Анимация

public class ViewAnimationUtils {

    public  static void expandOrCollapse(final View v,String exp_or_colpse) {
        TranslateAnimation anim = null;
        if(exp_or_colpse.equals("expand"))
        {
            anim = new TranslateAnimation(0.0f, 0.0f, -v.getHeight(), 0.0f);
            v.setVisibility(View.VISIBLE);
        }
        else{
            anim = new TranslateAnimation(0.0f, 0.0f, 0.0f, -v.getHeight());
            Animation.AnimationListener collapselistener= new Animation.AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {
                }

                @Override
                public void onAnimationRepeat(Animation animation) {
                }

                @Override
                public void onAnimationEnd(Animation animation) {
                    v.setVisibility(View.GONE);
                }
            };

            anim.setAnimationListener(collapselistener);
        }

        // To Collapse
        //

        anim.setDuration(300);
        anim.setInterpolator(new AccelerateInterpolator(0.5f));
        v.startAnimation(anim);
    }

    public static void expand(final View v) {
        v.measure(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        final int targtetHeight = v.getMeasuredHeight();

        v.getLayoutParams().height = 0;
        v.setVisibility(View.VISIBLE);
        Animation a = new Animation()
        {
            @Override
            protected void applyTransformation(float interpolatedTime, Transformation t) {
                v.getLayoutParams().height = interpolatedTime == 1
                        ? ViewGroup.LayoutParams.WRAP_CONTENT
                        : (int)(targtetHeight * interpolatedTime);
                v.requestLayout();
            }

            @Override
            public boolean willChangeBounds() {
                return true;
            }
        };

        a.setDuration(200);
        v.startAnimation(a);
    }

    public static void collapse(final View v) {
        final int initialHeight = v.getMeasuredHeight();

        Animation a = new Animation()
        {
            @Override
            protected void applyTransformation(float interpolatedTime, Transformation t) {
                if(interpolatedTime == 1){
                    v.setVisibility(View.GONE);
                }else{
                    v.getLayoutParams().height = initialHeight - (int)(initialHeight * interpolatedTime);
                    v.requestLayout();
                }
            }

            @Override
            public boolean willChangeBounds() {
                return true;
            }
        };

        a.setDuration(100);
        v.startAnimation(a);
    }
}

здесь xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="16dp"
        android:focusableInTouchMode="true"
        android:layout_gravity="bottom">

    <ScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scrollbars="none">

        <androidx.constraintlayout.widget.ConstraintLayout android:layout_width="match_parent"
                                                           android:layout_height="wrap_content">


            <Button
                    android:layout_width="0dp"
                    android:layout_height="48dp"
                    android:textSize="16sp"
                    android:textColor="@color/hard_white"
                    android:lineSpacingExtra="10sp"
                    android:gravity="center"
                    android:text="@string/continuee"
                    android:elevation="2dp"
                    android:textAllCaps="false"
                    android:background="@drawable/radius_background_lipstick"
                    android:id="@+id/btn_login" app:layout_constraintEnd_toEndOf="parent"
                    android:enabled="false"
                    android:layout_marginEnd="16dp"
                    android:layout_marginRight="16dp"
                    app:layout_constraintStart_toStartOf="parent"
                    android:layout_marginLeft="16dp"
                    android:layout_marginStart="16dp"
                    app:fontFamily="@font/akkuratprobold"
                    app:layout_constraintHorizontal_bias="0.0"
                    android:layout_marginTop="36dp"
                    app:layout_constraintTop_toBottomOf="@+id/textView17"
                    app:layout_constraintBottom_toBottomOf="parent" android:layout_marginBottom="8dp"/>

            <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="13sp"
                    android:textColor="#747474"
                    android:text="Pound Sterling"
                    app:fontFamily="@font/akkuratproregular"
                    android:id="@+id/textView17"
                    app:layout_constraintTop_toBottomOf="@+id/textView18" android:layout_marginStart="16dp"
                    app:layout_constraintStart_toStartOf="parent" android:layout_marginLeft="16dp"/>

            <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="16sp"
                    android:textColor="#2d2d2d"
                    android:lineSpacingExtra="10sp"
                    android:text="Cash amount"
                    app:fontFamily="@font/akkuratprobold"
                    android:id="@+id/textView18"
                    android:layout_marginTop="48dp"
                    app:layout_constraintTop_toBottomOf="@+id/textView19" android:layout_marginStart="16dp"
                    app:layout_constraintStart_toStartOf="parent" android:layout_marginLeft="16dp"/>

            <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="15dp"
                    android:textSize="13sp"
                    android:textColor="#747474"
                    app:fontFamily="@font/akkuratproregular"
                    android:lineSpacingExtra="7sp"
                    android:text="Amount you’d like to buy"
                    android:id="@+id/textView19"
                    app:layout_constraintTop_toBottomOf="@+id/view" android:layout_marginStart="16dp"
                    app:layout_constraintStart_toStartOf="parent" android:layout_marginLeft="16dp"
                    android:layout_marginTop="12dp"/>
            <EditText
                    android:layout_width="100dp"
                    android:layout_height="wrap_content"
                    android:inputType="number"
                    android:ems="10"
                    android:gravity="center"
                    android:textSize="30sp"
                    android:background="#70FFFFFF"
                    android:textColor="#2d2d2d"
                    android:lineSpacingExtra="-4sp"
                    app:fontFamily="@font/akkuratproregular"
                    android:id="@+id/editText2"
                    android:text="100" app:layout_constraintEnd_toEndOf="@+id/btn_login"
                    android:layout_marginTop="8dp"
                    app:layout_constraintTop_toTopOf="@+id/textView18"
                    app:layout_constraintBottom_toBottomOf="@+id/textView17" app:layout_constraintVertical_bias="1.0"
                    app:layout_constraintStart_toEndOf="@+id/textView17" android:layout_marginStart="8dp"
                    android:layout_marginLeft="8dp" app:layout_constraintHorizontal_bias="1.0"/>

            <View android:layout_width="379dp" android:layout_height="1dp"
                  android:background="@color/greyish"
                  android:alpha="0.5"
                  android:id="@+id/view"
                  app:layout_constraintTop_toBottomOf="@+id/constraintLayout5"
                  android:layout_marginStart="8dp" app:layout_constraintStart_toStartOf="parent"
                  android:layout_marginLeft="8dp" android:layout_marginEnd="8dp"
                  app:layout_constraintEnd_toEndOf="parent"
                  android:layout_marginRight="8dp" android:layout_marginTop="16dp"/>

            <View android:layout_width="379dp" android:layout_height="1dp"
                  android:background="@color/greyish"
                  android:alpha="0.5"
                  android:id="@+id/view2"
                  app:layout_constraintTop_toBottomOf="@+id/imageView9"
                  android:layout_marginTop="12dp" android:layout_marginStart="8dp"
                  app:layout_constraintStart_toStartOf="parent" android:layout_marginLeft="8dp"
                  android:layout_marginEnd="8dp" app:layout_constraintEnd_toEndOf="parent"
                  android:layout_marginRight="8dp"/>
            <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="16sp"
                    android:textColor="#2d2d2d"
                    android:lineSpacingExtra="10sp"
                    app:fontFamily="@font/akkuratprobold"
                    android:text="Order type"
                    android:id="@+id/textView20"
                    app:layout_constraintTop_toBottomOf="@+id/view2"
                    android:layout_marginTop="16dp" android:layout_marginStart="16dp"
                    app:layout_constraintStart_toStartOf="parent" android:layout_marginLeft="16dp"/>

            <androidx.constraintlayout.widget.ConstraintLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" android:layout_marginTop="8dp"
                    tools:layout_editor_absoluteX="0dp" app:layout_constraintTop_toBottomOf="@+id/textView20"
                    android:id="@+id/constraintLayout5"
                    android:visibility="gone">

                <ImageView
                        android:layout_width="15dp"
                        android:layout_height="15dp" app:srcCompat="@drawable/ic_tick"
                        android:id="@+id/imageView13" app:layout_constraintEnd_toEndOf="parent"
                        android:layout_marginEnd="24dp" android:layout_marginRight="24dp"
                        app:layout_constraintTop_toTopOf="@+id/textView23"
                        app:layout_constraintBottom_toBottomOf="@+id/textView23"/>

                <TextView
                        android:layout_width="0dp"
                        android:layout_height="40dp"
                        android:gravity="center|left"
                        android:textSize="16sp"
                        android:textColor="#2d2d2d"
                        android:lineSpacingExtra="10sp"
                        app:fontFamily="@font/akkuratprobold"
                        android:text="Cash"
                        android:id="@+id/textView23"
                        android:layout_marginEnd="16dp"
                        app:layout_constraintEnd_toEndOf="parent" android:layout_marginRight="16dp"
                        android:layout_marginStart="16dp" app:layout_constraintStart_toStartOf="parent"
                        android:layout_marginLeft="16dp" app:layout_constraintHorizontal_bias="0.0"
                        android:layout_marginTop="8dp" app:layout_constraintTop_toTopOf="parent"/>
                <TextView
                        android:layout_width="0dp"
                        android:layout_height="40dp"
                        android:gravity="center|left"
                        android:textSize="16sp"
                        android:textColor="#2d2d2d"
                        android:lineSpacingExtra="10sp"
                        app:fontFamily="@font/akkuratprobold"
                        android:text="Principal"
                        android:id="@+id/textView27"
                        android:layout_marginEnd="16dp"
                        app:layout_constraintEnd_toEndOf="parent" android:layout_marginRight="16dp"
                        android:layout_marginStart="16dp" app:layout_constraintStart_toStartOf="parent"
                        android:layout_marginLeft="16dp" app:layout_constraintHorizontal_bias="0.0"
                        android:layout_marginTop="8dp" app:layout_constraintTop_toBottomOf="@+id/textView23"/>

            </androidx.constraintlayout.widget.ConstraintLayout>


            <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="16sp"
                    android:textColor="#2d2d2d"
                    android:lineSpacingExtra="10sp"
                    android:gravity="end"
                    app:fontFamily="@font/akkuratprobold"
                    android:text="Cash"
                    android:id="@+id/textView14"
                    app:layout_constraintTop_toBottomOf="@+id/view2"
                    android:layout_marginTop="16dp" app:layout_constraintEnd_toStartOf="@+id/imageView12"
            />


            <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="13sp"
                    android:textColor="#747474"
                    android:gravity="center_horizontal"
                    app:fontFamily="@font/akkuratproregular"
                    android:text="Senior Secured"
                    android:id="@+id/textView21"
                    app:layout_constraintTop_toBottomOf="@+id/textView22" android:layout_marginStart="16dp"
                    app:layout_constraintStart_toStartOf="parent" android:layout_marginLeft="16dp"/>

            <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="13sp"
                    android:textColor="#747474"
                    android:gravity="center_horizontal"
                    app:fontFamily="@font/akkuratproregular"
                    android:text="Order Type"
                    android:visibility="gone"
                    android:id="@+id/textView26"
                    app:layout_constraintTop_toBottomOf="@+id/view2" android:layout_marginStart="16dp"
                    app:layout_constraintStart_toStartOf="parent" android:layout_marginLeft="16dp"
                    android:layout_marginTop="12dp"/>
            <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="16sp"
                    android:textColor="#2d2d2d"
                    android:lineSpacingExtra="10sp"
                    android:text="Company"
                    app:fontFamily="@font/akkuratprobold"
                    android:id="@+id/textView22"
                    android:layout_marginTop="16dp"
                    app:layout_constraintTop_toTopOf="parent" android:layout_marginStart="16dp"
                    app:layout_constraintStart_toStartOf="parent" android:layout_marginLeft="16dp"/>
            <ImageView
                    android:layout_width="40dp"
                    android:padding="5dp"
                    android:layout_height="40dp" app:srcCompat="@drawable/aston_martin_logo"
                    android:id="@+id/imageView9" android:layout_marginTop="8dp"
                    app:layout_constraintTop_toTopOf="@+id/textView22"
                    android:background="@drawable/radius_corner_grey"
                    app:layout_constraintBottom_toBottomOf="@+id/textView21" app:layout_constraintEnd_toEndOf="parent"
                    android:layout_marginEnd="16dp" android:layout_marginRight="16dp"
                    app:layout_constraintVertical_bias="0.47"/>
            <ImageView
                    android:layout_width="25dp"
                    android:layout_height="25dp" app:srcCompat="@drawable/ic_down"
                    android:id="@+id/imageView12" app:layout_constraintEnd_toEndOf="parent"
                    android:layout_marginEnd="16dp" android:layout_marginRight="16dp"
                    app:layout_constraintTop_toTopOf="@+id/textView14"
                    app:layout_constraintBottom_toBottomOf="@+id/textView14"/>



        </androidx.constraintlayout.widget.ConstraintLayout>
    </ScrollView>

</androidx.constraintlayout.widget.ConstraintLayout>
...