android - 查看按钮及其下方的列表 fragment

标签 android android-layout android-fragments

我正在尝试使用按钮创建 View ,并使用此按钮下的列表创建 fragemtn。问题是列表从按钮顶部开始而不是从底部开始,它看起来像这样:

enter image description here

布局代码:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".activities.BluetoothActivity">

    <Button
            android:text="@string/scan"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/BluetoothScanButton"
            app:layout_constraintEnd_toEndOf="parent"
            android:layout_marginEnd="8dp"
            app:layout_constraintStart_toStartOf="parent"
            android:layout_marginStart="8dp"
            android:layout_marginTop="40dp"
            app:layout_constraintTop_toTopOf="parent"/>


    <fragment
            android:id="@+id/BluetoothDevicesFragment"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:name="com.tatara.taffico.DeviceListFragment"
            app:layout_constraintEnd_toEndOf="parent"
            android:layout_marginEnd="8dp"
            app:layout_constraintStart_toStartOf="parent"
            android:layout_marginStart="8dp"
            app:layout_constraintBottom_toBottomOf="parent"
            android:layout_marginTop="8dp"
            app:layout_constraintTop_toBottomOf="@+id/BluetoothScanButton"/>
</android.support.constraint.ConstraintLayout>

谁能帮我解决这个问题吗?

最佳答案

您应该添加 android:layout_height="0dp" fragment 部分。

 <fragment
        android:id="@+id/BluetoothDevicesFragment"
        android:layout_width="match_parent"
        android:layout_height="0dp"

ConstraintLayout

You can also define one dimension of a widget as a ratio of the other one. In order to do that, you need to have at least one constrained dimension be set to 0dp (i.e., MATCH_CONSTRAINT).

关于android - 查看按钮及其下方的列表 fragment ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55965060/

相关文章:

android - 谷歌地图 :onMapReadyCallback can not be applied to this activity

android - Android ScrollView 中的 VerticalScrollExtent 是什么?

android - 更改太多布局的可见性可能会导致性能问题吗?

android - 如何在微调器中自定义对话框大小

android - 保存 fragment 状态或保存文件并从中更新 - Android

android - 操作栏按钮未显示在 fragment 中

Android - 底部导航标签调用的 fragment 每次都重新加载

javascript - HTML5 Canvas : Prevent moving on phone

android - 在 HttpAsyncTask().execute() 中传递参数

android - 在 android 11 上,状态栏不会隐藏