簡體   English   中英

如果屏幕上無法容納一個按鈕,請在ConstraintLayout中將其放置在另一個按鈕下面

[英]Place one button below another in ConstraintLayout if they can't fit on screen

我想將按鈕水平放置在大屏幕上,垂直放置在小屏幕上(如果它們不適合屏幕分辨率)。 我可以使用ConstraintLayout來做到這一點,而不必在xml中創建兩個取決於屏幕分辨率的布局嗎? 我不知道如何為該行為設置“約束”?

現在像這樣工作

這是我在xml中的布局

<?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">

    <Button
       android:id="@+id/button5"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="First button"
       app:layout_constraintTop_toTopOf="parent"
       app:layout_constraintBottom_toBottomOf="parent"
       app:layout_constraintLeft_toLeftOf="parent"
       app:layout_constraintRight_toLeftOf="@+id/button3" />

    <Button
       android:id="@+id/button3"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="Second button"
       app:layout_constraintTop_toTopOf="parent"
       app:layout_constraintBottom_toBottomOf="parent"
       app:layout_constraintLeft_toRightOf="@+id/button5"
       app:layout_constraintRight_toRightOf="parent" />

</android.support.constraint.ConstraintLayout>

僅使用ConstraintLayout便無法做到這一點。 它沒有為您提供一種為鏈中的Views創建某種linebreak的方法。

有多個庫可以輕松地做到這一點。 但是您將不得不引入另一種布局。 例如android-flowlayout

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM