[英]Place one button below another in ConstraintLayout if they can't fit on screen
I would like to place buttons horizontally on large screens and vertically on small screens (if they can't fit in screen resolution). 我想将按钮水平放置在大屏幕上,垂直放置在小屏幕上(如果它们不适合屏幕分辨率)。 Can I do it by using ConstraintLayout without creating two layouts in xml which depend on screen resolution?
我可以使用ConstraintLayout来做到这一点,而不必在xml中创建两个取决于屏幕分辨率的布局吗? I don't know how can I setup "constraints" for that behaviour?
我不知道如何为该行为设置“约束”?
It is my layout in 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>
You won't be able to do that with just ConstraintLayout
. 仅使用
ConstraintLayout
便无法做到这一点。 It does not provide you with a way to create sort of a linebreak
for Views
in a chain. 它没有为您提供一种为链中的
Views
创建某种linebreak
的方法。
There are multiple libraries that can easily let to do that. 有多个库可以轻松地做到这一点。 But you will have to introduce another layout.
但是您将不得不引入另一种布局。 Eg
android-flowlayout
. 例如
android-flowlayout
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.