A.A*_*omi 6 android android-constraintlayout
我有一个包含2个视图的屏幕,一个map(顶部)和一个recycler(底部)。规则很简单。
回收者视图可以扩展到屏幕中间,如果需要更多空间,则应滚动查看,地图将占据其余空间。地图的空间..
我正在尝试使用约束布局来实现这一目标,同时也试图避免涉及计算的解决方案。
这是我的代码
<?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_height="match_parent"
android:background="@color/white"
tools:context="com.qmic.itraffic.ui.activities.crowdsourcing.CrowdSourceReportingDetailsActivity">
<androidx.constraintlayout.widget.Guideline
android:id="@+id/halfScreenGuideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.5" />
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@+id/categories"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:background="@color/manatee"
/>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/categories"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:clipToPadding="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/halfScreenGuideline" />
</androidx.constraintlayout.widget.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
我的问题是我可以仅使用xml(约束布局)来实现此行为吗?还是我需要进行计算?
您可以在您的 recyclerview xml 中尝试以下代码吗
android:layout_height="wrap_content"
app:layout_constrainedHeight="true"
Run Code Online (Sandbox Code Playgroud)
更改高度以换行内容并添加第二行。这样,recyclerview 的高度应该与其内容相同,但永远不会超过准则/约束。
| 归档时间: |
|
| 查看次数: |
84 次 |
| 最近记录: |