【发布时间】:2018-10-28 05:29:32
【问题描述】:
我在 Views 画布的顶部添加了一个 XML 布局。 “按钮到底部”按钮我希望它们应该被捕捉到屏幕底部但是 app:layout_constraintBottom_toBottomOf="parent" 不起作用。
如何让底部线性布局贴紧到屏幕底部,让顶部线性布局贴紧到屏幕顶部?
这里是xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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:id="@+id/constlayout_matchreplay_actionbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<Button
android:id="@+id/button_matchreplay_back"
android:layout_width="150dip"
android:layout_height="50dip"
android:text="back" />
<Spinner
android:id="@+id/spinner_matchreplay_matchselect"
android:layout_width="200dip"
android:layout_height="45dip"
android:background="@android:drawable/btn_dropdown"
android:spinnerMode="dropdown" />
<Button
android:id="@+id/button_matchreplay_forward"
android:layout_width="150dip"
android:layout_height="50dip"
android:text="forward" />
<Button
android:id="@+id/button_matchreplay_empty_room"
android:layout_width="75dip"
android:layout_height="50dip"
android:text="DELETE"
android:textSize="8dip" />
<Button
android:id="@+id/button_matchreplay_empty_all"
android:layout_width="75dip"
android:layout_height="50dip"
android:text="EMPTY-ALL"
android:textSize="8dip" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:orientation="horizontal"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<Button
android:id="@+id/button4"
android:layout_width="150dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button to Bottom" />
<Button
android:id="@+id/button5"
android:layout_width="150dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button to Bottom" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
【问题讨论】:
-
由于您的
ConstraintLayout的高度为match_parent,那么它的父视图的高度可能为wrap_content,从而导致视图折叠。所以试着把父母的身高也改成match_parent,或者干脆更高。
标签: android xml android-constraintlayout