【问题标题】:how to put recyclerview on bottom of spinner如何将recyclerview放在微调器的底部
【发布时间】:2021-11-17 10:05:36
【问题描述】:

我在片段中使用约束布局。我设置了 TopToBottomOf,虽然它没有达到底部。

<Spinner
        android:id="@+id/filterSpinner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp"
        android:layout_marginRight="10dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"

        tools:ignore="SpeakableTextPresentCheck,TouchTargetSizeCheck" />

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recyclerViewCallLog"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/filterSpinner" />

我已将其设置为app:layout_constraintTop_toBottomOf="@+id/filterSpinner"。我想把 recyclerView 放在 Spinner 的底部。我想无边距地实现它。

似乎约束布局在页面中不起作用。因此我展示了整个 xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_marginTop="30dp"
    android:layout_height="match_parent"
    tools:context=".fragment.DialerFragment">

    <Spinner
        android:id="@+id/filterSpinner"
        android:layout_width="match_parent"
        android:layout_height="20dp"
        android:layout_marginTop="5dp"
        android:layout_marginRight="10dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"

        tools:ignore="SpeakableTextPresentCheck,TouchTargetSizeCheck" />

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recyclerViewCallLog"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="20dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/filterSpinner" />

    <com.futuremind.recyclerviewfastscroll.FastScroller
        android:id="@+id/fastscroll_dialer"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:orientation="vertical"
        app:fastscroll__bubbleColor="#5e64ce"
        app:fastscroll__handleColor="#8f93d1"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="@id/recyclerViewCallLog"
        app:layout_constraintTop_toTopOf="@+id/recyclerViewCallLog" />

</androidx.constraintlayout.widget.ConstraintLayout>

【问题讨论】:

    标签: android xml constraints android-constraintlayout


    【解决方案1】:

    您只需为RecyclerView 执行0dp 高度。如下所示

    <?xml version="1.0" encoding="utf-8"?>
    <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_marginTop="30dp"
        android:layout_height="match_parent">
    
        <Spinner
            android:id="@+id/filterSpinner"
            android:layout_width="match_parent"
            android:layout_height="20dp"
            android:layout_marginTop="5dp"
            android:layout_marginRight="10dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
    
            tools:ignore="SpeakableTextPresentCheck,TouchTargetSizeCheck" />
    
        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/recyclerViewCallLog"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_marginTop="20dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/filterSpinner" />
    
        <com.futuremind.recyclerviewfastscroll.FastScroller
            android:id="@+id/fastscroll_dialer"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:orientation="vertical"
            app:fastscroll__bubbleColor="#5e64ce"
            app:fastscroll__handleColor="#8f93d1"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="@id/recyclerViewCallLog"
            app:layout_constraintTop_toTopOf="@+id/recyclerViewCallLog" />
    
    </androidx.constraintlayout.widget.ConstraintLayout>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-29
      • 1970-01-01
      • 2022-09-12
      • 1970-01-01
      • 2022-07-21
      • 1970-01-01
      • 2021-09-13
      • 1970-01-01
      相关资源
      最近更新 更多