我正在尝试在ConstraintLayout内另一个ConstraintLayout(“ clientData)下面显示一个RecyclerView(” mapRecyclerView“),但是它表现出一种奇怪的行为:RecyclerView(” mapRecyclerView“)在另一个ConstraintLayout( “ clientData”),如果此ConstraintLayout的宽度为特定dp,则recyclerview会显示正常,但如果ConstraintLayout的宽度为“ match_constraint”,则不再显示RecyclerView,并且永远不会调用RecyclerView的“ afterMeasured”事件,这是布局的XML:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="0dp"
android:layout_height="?attr/actionBarSize"
android:minHeight="?attr/actionBarSize"
android:background="@android:color/white"
android:elevation="4dp" app:layout_constraintStart_toStartOf="parent"
android:fontFamily="@font/gotham_rounded_book"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" android:theme="@style/custom_toolbar"/>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="0dp"
android:layout_height="wrap_content" app:layout_constraintTop_toBottomOf="@+id/toolbar"
app:layout_constraintStart_toStartOf="parent"
android:id="@+id/clientData" android:background="@color/white"
app:layout_constraintEnd_toEndOf="parent">
<TextView
android:text="1"
android:layout_width="35dp"
android:layout_height="35dp"
android:id="@+id/activeServiceNumber"
android:background="@drawable/button_yellow_round_border" android:textAlignment="center"
android:textSize="18sp"
app:layout_constraintTop_toTopOf="@+id/name" android:layout_marginStart="8dp"
app:layout_constraintStart_toStartOf="parent"
android:fontFamily="@font/gotham_rounded_medium"
android:paddingTop="6dp" android:textColor="@color/white" android:layout_marginTop="8dp"/>
<TextView
android:text="TextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/name"
app:layout_constraintStart_toEndOf="@+id/activeServiceNumber" android:layout_marginStart="8dp"
android:fontFamily="@font/gotham_rounded_medium" android:textColor="@color/colorPrimaryText"
android:textSize="16sp" android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp" app:layout_constraintBottom_toTopOf="@+id/client"
app:layout_constraintTop_toTopOf="parent" android:layout_marginTop="8dp"
app:layout_constraintEnd_toStartOf="@+id/directionsBtn"/>
<TextView
android:text="TextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/client"
app:layout_constraintStart_toEndOf="@+id/activeServiceNumber" android:layout_marginStart="8dp"
android:fontFamily="@font/gotham_rounded_light" android:textSize="15sp" android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toTopOf="@+id/address"
app:layout_constraintEnd_toStartOf="@+id/directionsBtn"/>
<TextView
android:text="TextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/address"
app:layout_constraintStart_toEndOf="@+id/activeServiceNumber" android:layout_marginStart="8dp"
android:fontFamily="@font/gotham_rounded_light" android:textSize="13sp" android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toTopOf="@+id/phone"
app:layout_constraintEnd_toStartOf="@+id/directionsBtn"/>
<TextView
android:text="TextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/phone"
app:layout_constraintStart_toEndOf="@+id/activeServiceNumber" android:layout_marginStart="8dp"
android:textSize="13sp" android:fontFamily="@font/gotham_rounded_light" android:layout_marginEnd="8dp"
app:layout_constraintBottom_toBottomOf="parent" android:layout_marginBottom="16dp"
app:layout_constraintEnd_toStartOf="@+id/directionsBtn"/>
<Button
android:layout_width="wrap_content"
android:layout_height="0dp"
android:id="@+id/directionsBtn"
app:layout_constraintEnd_toEndOf="parent"
android:text="Mostrar \nRuta"
android:drawableTop="@drawable/ic_go_to_route" android:textAllCaps="false"
android:background="@color/white"
android:padding="10dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/ongoingServiceMap"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
android:clickable="true"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
tools:context="com.cargamos.cargamosdriver.views.service.OngoingServiceActivity"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintBottom_toBottomOf="parent" android:focusable="true"
app:layout_constraintTop_toBottomOf="@+id/clientData"/>
<androidx.recyclerview.widget.RecyclerView
android:layout_width="wrap_content"
android:layout_marginTop="32dp"
android:layout_marginBottom="32dp"
app:layout_constraintStart_toStartOf="@+id/ongoingServiceMap"
android:layout_marginStart="8dp"
android:id="@+id/mapRecyclerView"
android:background="@color/white"
app:layout_constraintBottom_toTopOf="@+id/confirmArrivalSlider"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@+id/clientData"/>
<com.ncorti.slidetoact.SlideToActView
android:id="@+id/confirmArrivalSlider"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:text="Confirmar llegada"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:slider_height="60dp"
app:area_margin="4dp"
app:outer_color="@color/colorPrimary" app:text_style="bold" app:text_size="18dp"
android:layout_marginStart="32dp" android:layout_marginBottom="24dp" android:layout_marginEnd="32dp"/>
</androidx.constraintlayout.widget.ConstraintLayout>
答案 0 :(得分:0)
根据RecyclerView
中的内容,您可能希望将RecyclerView
的宽度设置为match_parent
。
顺便说一句,我无法重现您在预览中描述的问题