我正在尝试使用按钮创建 View ,并使用此按钮下的列表创建 fragemtn。问题是列表从按钮顶部开始而不是从底部开始,它看起来像这样:
布局代码:
<?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"
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/