При установке видимости GONE для этой кнопки происходит рывок - PullRequest
0 голосов
/ 28 марта 2020

See this image is having a jerk when I set visibility gone

Я использую android: animateLayoutChanges = "true" здесь я делюсь макетом просмотра карты:

<?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:layout_width="280dp"
    android:layout_height="match_parent"
    android:gravity="bottom"
    android:orientation="vertical">

    <androidx.cardview.widget.CardView
        android:id="@+id/cvRegisteredPharmacy"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginBottom="30dp"
        app:cardBackgroundColor="@color/colorAccent"
        app:cardUseCompatPadding="true">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:animateLayoutChanges="true"
            android:orientation="vertical">

            <ImageView
                android:id="@+id/ivPharmacy"
                android:layout_width="match_parent"
                android:layout_height="100dp"
                android:layout_weight="0.25"
                android:background="@color/colorWhite" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:padding="15dp">

                <TextView
                    android:id="@+id/tvPharmacyName"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="5dp"
                    android:text="Pharmacy Name"
                    android:textColor="@color/colorWhite"
                    android:textSize="16sp"
                    android:textStyle="bold" />

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <RatingBar
                        android:id="@+id/rbPharmacyRating"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:numStars="5"
                        style="?android:attr/ratingBarStyleSmall"
                        android:rating="3.5"
                        android:progressTint="@color/colorPrimary"
                        android:progressBackgroundTint="@color/colorGrey" />


                <TextView
                    android:id="@+id/tvPharmacyInfo"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:layout_marginLeft="5dp"
                    android:text="3.5"
                    android:textColor="@color/colorWhite"
                    android:textSize="12sp" />

                </LinearLayout>

                <TextView
                    android:id="@+id/tvPharmacyAddress"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:text="Pharmacy Address, 1/2 Main St NW, Monteral, QC"
                    android:textColor="@color/colorWhite"
                    android:textSize="14sp" />

            </LinearLayout>

            <Button
                android:id="@+id/btnSelectPharmacy"
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:layout_marginLeft="15dp"
                android:layout_marginRight="15dp"
                android:layout_marginBottom="15dp"
                android:background="@drawable/btn_bg_white"
                android:text="Select Pharmacy"
                android:textColor="@color/colorAccent"
                android:visibility="gone" />

        </LinearLayout>

    </androidx.cardview.widget.CardView>

</LinearLayout>

Вот полный макет, который я сделал

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.PharmacyMapActivity">

<fragment
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<androidx.recyclerview.widget.RecyclerView
    android:id="@+id/rvPharmaciesList"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"/>

</RelativeLayout>

Кроме того, я делюсь простым кодом, где я устанавливаю видимость этой кнопки:

if (holder.btnSelectPharmacy.getVisibility() == View.VISIBLE){
                    holder.btnSelectPharmacy.setVisibility(View.GONE);
                } else {
                    holder.btnSelectPharmacy.setVisibility(View.VISIBLE);
}

Я пробовал много решений, включая просмотр анимации, аниматор объектов, расширяемый макет (через библиотеку), но пока не повезло! с нетерпением жду ваших предложений. У меня есть обходной путь, чтобы поднять карту, но затем я хочу, чтобы моя карта развернулась вверх так же, как на картинке выше.

1 Ответ

0 голосов
/ 30 марта 2020

При использовании автоматической анимации макета c на дочернем узле, результатом будет то, что родительский узел просто привязывается к layout_alignParentBottom & wrap_content, когда дочерний узел равен View.GONE.

Объединение двух анимаций может сделать его менее резким. Я имею в виду, что CardView нужна анимация высоты; либо синхронно, либо когда дочерний узел равен View.GONE. На самом деле, при анимации дочернего узла на высоту 0dp это также будет анимировать высоту родительского узла, так как это wrap_content; установка значения stati c для высоты также предотвратит его привязку. Кроме того, анимация до View.INVISBLE и последующая анимация ее высоты будут препятствовать привязке родительского узла. Извините за то, что не предоставили готовое решение, но объясните, почему оно ведет себя одинаково, и как оно может работать, все же лучше, чем отсутствие ответа.

...