单击回收者视图上的项目后无法聚焦到地图上

问题描述 投票:0回答:1

我正在尝试使用回收者视图在地图片段上显示项目。回收站视图是在地图片段内定义的。当我从“回收者”视图中单击某个项目时,我通过调用listname.clear()和adapter.notifyDataSetChanged()来重置适配器数据。回收者视图已清除,但我无法再次移动地图。

<?xml version="1.0" encoding="utf-8"?>
<fragment 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:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:descendantFocusability="blocksDescendants"
android:layout_height="match_parent"
tools:context=".Nearby" >

<androidx.constraintlayout.widget.ConstraintLayout
    android:id="@+id/mapConstraint"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <Button
        android:id="@+id/selectListBtn"
        android:layout_width="368dp"
        android:layout_height="56dp"
        android:layout_marginStart="10dp"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="10dp"
        android:layout_marginEnd="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginBottom="7dp"
        android:background="@color/design_default_color_primary_dark"
        android:text="Select Your List"
        android:textColor="#FFFFFF"
        map:layout_constraintBottom_toTopOf="@+id/selectListRecycler"
        map:layout_constraintEnd_toEndOf="parent"
        map:layout_constraintStart_toStartOf="parent"
        map:layout_constraintTop_toTopOf="parent" />

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/selectListRecycler"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginStart="5dp"
        android:layout_marginLeft="5dp"
        android:layout_marginEnd="5dp"
        android:layout_marginRight="5dp"
        android:layout_marginBottom="59dp"
        map:layout_constraintBottom_toBottomOf="parent"
        map:layout_constraintEnd_toEndOf="parent"
        map:layout_constraintStart_toStartOf="parent"
        map:layout_constraintTop_toBottomOf="@+id/selectListBtn" />
</androidx.constraintlayout.widget.ConstraintLayout>

以某种方式,我通过将recyclerview的可见性设置为View.GONE设法重新获得了对地图的关注,但是该按钮位于片段的中间,对齐方式出错。

recyclerView = (RecyclerView) rootView.findViewById(R.id.selectListRecycler);
                ArrayList<TList> tempList = tLists;
                parent = (ViewGroup) recyclerView.getParent();
                //RecyclerView tempView = (RecyclerView) rootView.findViewById(R.id.selectListRecycler);
                adapter = new TListRecyclerAdapter(tempList);

                recyclerView.setHasFixedSize(false);
                recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
                recyclerView.setAdapter(adapter);

                recyclerView.addOnItemTouchListener(new RecyclerTouchListener(getContext(),
                        recyclerView, new ClickListener() {
                    @Override
                    public void onClick(View view, final int position) {
                        selectedList = tLists.get(position);
                        tempList.clear();
                        adapter.notifyDataSetChanged();

                    }

                    @Override
                    public void onLongClick(View view, int position) {
                        //Toast.makeText(Nearby.this, "Long press on position :"+position,
                        //        Toast.LENGTH_LONG).show();
                        String x="";
                    }
                }));

Before clicking select list

After clicking select list

After setting recyclerview visibility to GONE

android android-recyclerview maps
1个回答
0
投票

Option-1:只需从map:layout_constraintBottom_toTopOf="@+id/selectListRecycler"中删除Button

<Button
    android:id="@+id/selectListBtn"
    android:layout_width="368dp"
    android:layout_height="56dp"
    android:layout_marginStart="10dp"
    android:layout_marginLeft="10dp"
    android:layout_marginTop="10dp"
    android:layout_marginEnd="10dp"
    android:layout_marginRight="10dp"
    android:layout_marginBottom="7dp"
    android:background="@color/design_default_color_primary_dark"
    android:text="Select Your List"
    android:textColor="#FFFFFF"
    map:layout_constraintEnd_toEndOf="parent"
    map:layout_constraintStart_toStartOf="parent"
    map:layout_constraintTop_toTopOf="parent" />

选项-2:代替androidx.constraintlayout.widget.ConstraintLayout,请使用LinearLayout垂直方向。

android:orientation="vertical"
© www.soinside.com 2019 - 2024. All rights reserved.