gpt4 book ai didi

android - 应用程序 :layout_constraintBottom_toBottomOf ="parent" for inflated XML layout

转载 作者:行者123 更新时间:2023-11-29 00:58:16 25 4
gpt4 key购买 nike

enter image description here

我在 View Canvas 的顶部扩展了一个 XML 布局。 “Button to Bottom”按钮我希望它们应该对齐到屏幕底部,但是 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 中使用 LinearLayout,因为 ConstraintLayout 允许您创建具有平面 View 层次结构的大型复杂布局(< strong>没有嵌套 View 组)。

请尝试以下方法

<?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:layout_width="match_parent"
android:layout_height="match_parent">


<Button
android:id="@+id/button_matchreplay_back"
android:layout_width="150dip"
android:layout_height="50dip"
android:layout_marginTop="5dp"
android:text="back"
app:layout_constraintEnd_toStartOf="@+id/spinner_matchreplay_matchselect"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Spinner
android:id="@+id/spinner_matchreplay_matchselect"
android:layout_width="200dip"
android:layout_height="45dip"
android:layout_marginStart="10dp"
android:layout_marginTop="5dp"
android:background="@android:drawable/btn_dropdown"
android:spinnerMode="dropdown"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/button_matchreplay_back"
app:layout_constraintTop_toTopOf="parent" />


<Button
android:id="@+id/button_matchreplay_forward"
android:layout_width="150dip"
android:layout_height="50dip"
android:layout_marginTop="15dp"
android:text="forward"
app:layout_constraintEnd_toStartOf="@+id/button_matchreplay_empty_all"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button_matchreplay_back" />

<Button
android:id="@+id/button_matchreplay_empty_all"
android:layout_width="75dip"
android:layout_height="50dip"
android:layout_marginStart="10dp"
android:layout_marginTop="15dp"
android:text="EMPTY-ALL"
android:textSize="8dip"
app:layout_constraintEnd_toStartOf="@+id/button_matchreplay_empty_room"
app:layout_constraintStart_toEndOf="@+id/button_matchreplay_forward"
app:layout_constraintTop_toBottomOf="@+id/button_matchreplay_back" />

<Button
android:id="@+id/button_matchreplay_empty_room"
android:layout_width="75dip"
android:layout_height="50dip"
android:layout_marginStart="10dp"
android:layout_marginTop="15dp"
android:text="DELETE"
android:textSize="8dip"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/button_matchreplay_empty_all"
app:layout_constraintTop_toBottomOf="@+id/button_matchreplay_back" />


<Button
android:id="@+id/button5"
android:layout_width="150dip"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:text="Button to Bottom"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/button4"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent" />

<Button
android:id="@+id/button4"
android:layout_width="150dip"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginBottom="5dp"
android:text="Button to Bottom"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/button5" />


</android.support.constraint.ConstraintLayout>

请看下面上面 xml 布局的最终​​截图

Constraint layout 有关详细信息,请参阅 ConstraintLayout

关于android - 应用程序 :layout_constraintBottom_toBottomOf ="parent" for inflated XML layout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53028632/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com