我有一个ConstraintLayout
,它包含3个水平按钮。我希望3个按钮具有固定的宽度,并且均匀分布在整个布局的宽度上。Android ConstraintLayout:三个按钮在宽度上均匀分布
回答
使用线性布局作为父布局和内部线性布局(水平)使用按钮和每个按钮使用重量属性= 1它将工作。
我知道使用线性布局的解决方案。你能帮我使用约束布局吗? –
试试这个工作对我来说...
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/button_save"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/button_save_text"
android:layout_marginStart="8dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="4dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toLeftOf="@+id/button_share"
app:layout_constraintHorizontal_chainStyle="spread" />
<Button
android:id="@+id/button_share"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/button_share_text"
android:layout_marginStart="4dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintLeft_toRightOf="@+id/button_save"
app:layout_constraintRight_toLeftOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />
</android.support.constraint.ConstraintLayout>
请参阅此链接了解更多关于此问题http://stackoverflow.com/questions/37518745/evenly-spacing-views-using-constraintlayout –
感谢它将工作 –
试试下面的代码
<?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/activity_main_inference"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_editor_absoluteX="0dp"
app:layout_editor_absoluteY="80dp"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="80dp">
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button7"
android:layout_marginTop="16dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="16dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
tools:layout_constraintRight_creator="1"
tools:layout_constraintLeft_creator="1" />
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button8"
app:layout_constraintTop_toTopOf="@+id/button7"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginStart="8dp"
app:layout_constraintRight_toLeftOf="@+id/button7"
android:layout_marginEnd="8dp" />
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button9"
app:layout_constraintBaseline_toBaselineOf="@+id/button7"
tools:layout_constraintRight_creator="1"
android:layout_marginEnd="7dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginStart="8dp"
app:layout_constraintLeft_toRightOf="@+id/button7" />
</android.support.constraint.ConstraintLayout>
这一个是真正的问题的答案。 –
- 1. 均匀分布在整个宽度
- 2. 是否可以在整个宽度上均匀分布按钮RELATIVE LAYOUT
- 3. 沿着屏幕宽度均匀分布的按钮
- 4. 三个按钮均匀分布线性布局
- 5. 如何在一行中按宽度均匀分布组件?
- 6. 水平分布的三个按钮均匀IOS
- 7. 在Xcode中均匀分布按钮
- 8. 在Android上均匀分布空间按钮
- 9. 需要均匀分布的按钮行
- 10. 使用Android Constraintlayout创建一排均匀分布的正方形
- 11. 最大宽度和最小宽度均匀分布的DIV
- 12. 在容器的整个高度和宽度上均匀分布DIV儿童
- 13. 分发按钮DIV均匀
- 14. 均匀间距按钮android
- 15. 如何布置三个均匀位于LinearLayout下的按钮?
- 16. 布局中间隔均匀的按钮
- 17. 在Android中嵌套线性布局以均匀分享高度和宽度
- 18. ConstraintLayout:平方视图,均匀分布,自动调整
- 19. PRNG均匀分布
- 20. 带有2个均匀间隔按钮的Android布局
- 21. 在表格布局的高度上均匀分布行
- 22. 在圆上均匀分布点
- 23. 在字母上均匀分布字母
- 24. 如何确保按CSS颠倒的按钮均匀分布?
- 25. 文本不换的均匀分布,甚至宽度Flexbox的
- 26. 不同宽度的均匀分布的图像?
- 27. 将非均匀分布转化为均匀分布
- 28. Android以编程方式创建四个均匀分布重量的按钮
- 29. 在Android进度条中均匀分布的图标
- 30. 屏幕上的三个按钮宽度Android
如果按钮宽度不同,则不起作用 – gjsalot