Метод setVisibility не работает должным образом ANDROID - PullRequest
0 голосов
/ 09 июля 2020

У меня есть файл fragment_map. xml. И есть ImageView. Это кнопка возврата (ее идентификатор - map_back_button). Я хочу, чтобы моя кнопка возврата отсутствовала при нажатии самой и была видна при нажатии элемента RecyclerView. Проблема в том, что метод setVisibility () не работает должным образом. Это заставляет мой ImageView исчезнуть на некоторое время, затем представление снова становится видимым.

fragment_map. xml file:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.motion.widget.MotionLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/map_root_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@mipmap/map_bg"
android:orientation="vertical"
app:layoutDescription="@xml/map_scroll"
android:animateLayoutChanges="true">

<FrameLayout
    android:id="@+id/map_top_panel_container"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@mipmap/home_top"
    android:orientation="vertical"
    android:padding="20dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <ImageView
        android:id="@+id/map_logo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/logo"
        android:src="@mipmap/logo_white" />

    <LinearLayout
        android:id="@+id/map_spinner_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/map_spinner_sector"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginEnd="15dp"
            android:layout_weight="1"
            android:background="@drawable/suggestions_bg"
            android:padding="3dp"
            android:paddingStart="10dp"
            android:text="Sektör"
            android:textColor="@color/blue_popular" />

        <TextView
            android:id="@+id/map_spinner_extension"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginEnd="15dp"
            android:layout_weight="1"
            android:background="@drawable/suggestions_bg"
            android:padding="3dp"
            android:paddingStart="10dp"
            android:text="Firma Uzantısı"
            android:textColor="@color/blue_popular" />


        <TextView
            android:id="@+id/map_spinner_sorting"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginEnd="15dp"
            android:layout_weight="1"
            android:background="@drawable/suggestions_bg"
            android:padding="3dp"
            android:paddingStart="10dp"
            android:text="Sıralama"
            android:textColor="@color/blue_popular" />


    </LinearLayout>


</FrameLayout>

<ImageView
    android:id="@+id/map_back_button"
    android:layout_width="24dp"
    android:layout_height="24dp"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@id/map_top_panel_container"
    android:layout_marginStart="20dp"
    android:layout_marginTop="10dp"
    android:src="@drawable/arrow_back"
    android:contentDescription="@string/indicator"/>


<TextView
    android:id="@+id/district_name_tv"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="20dp"
    android:layout_marginTop="10dp"
    android:layout_marginEnd="20dp"
    android:layout_marginBottom="5dp"
    android:textColor="@color/blue_popular"
    android:textSize="20sp"
    app:layout_constraintStart_toEndOf="@id/map_back_button"
    app:layout_constraintTop_toBottomOf="@id/map_top_panel_container" />

<LinearLayout
    android:id="@+id/map_container"
    android:layout_width="0dp"
    android:layout_height="280dp"
    app:layout_constraintTop_toBottomOf="@+id/district_name_tv"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    android:visibility="visible">

    <com.gxslash.suppline.main.map.Map
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />

</LinearLayout>

<View
    android:id="@+id/map_separator"
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:layout_marginStart="20dp"
    android:layout_marginTop="20dp"
    android:layout_marginEnd="20dp"
    android:background="@color/gray_for_line"
    app:layout_constraintTop_toBottomOf="@+id/map_container"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"/>

<androidx.recyclerview.widget.RecyclerView
    android:id="@+id/map_list"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_marginStart="20dp"
    android:layout_marginTop="10dp"
    android:layout_marginEnd="20dp"
    android:layout_marginBottom="@dimen/seventy_seven_margin"
    app:layout_constraintTop_toBottomOf="@+id/map_separator"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintBottom_toBottomOf="parent"/>

<ImageView
    android:id="@+id/map_return_button"
    android:layout_width="40dp"
    android:layout_height="40dp"
    android:layout_marginBottom="10dp"
    android:layout_marginEnd="10dp"
    android:src="@mipmap/return_button"
    app:layout_constraintBottom_toBottomOf="@id/map_list"
    app:layout_constraintEnd_toEndOf="@id/map_list"
    android:visibility="gone"/>

</androidx.constraintlayout.motion.widget.MotionLayout>

и связанные части из моего java file:

private DistrictListAdapter.OnDistrictClickListener recyclerViewItemClickListener = new DistrictListAdapter.OnDistrictClickListener() {
    @Override
    public void onDistrictClicked(int position) {
        String district = District.DISTRICTS[position].getDistrictName().toLowerCase();
        if (district.equals("nilüfer")) {
            backButton.setVisibility(View.VISIBLE);
        }
        else {
            firmList.clear();
            firmListAdapter.notifyDataSetChanged();
            Toast.makeText(activity, "Bu bölge için aktif veri bulunmamaktadır", Toast.LENGTH_SHORT).show();
        }
    }
};


private View.OnClickListener backButtonClicked = new View.OnClickListener(){
    @Override
    public void onClick(View v){
        mapPath.remove(mapPath.size() - 1);
        refreshMapPath();
        backButton.setVisibility(View.GONE);
        backButton.postInvalidate();
        mapList.setAdapter(districtAdapter);
    }
};

и

ImageView backButton = activity.findViewById(R.id.map_back_button);
backButton.setOnClickListener(backButtonClicked);

Это весь код, связанный с backButton. Я могу поделиться дополнительным кодом, если вам нужно. Спасибо

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...