android - 约束布局中两个等宽按钮
问题描述
如何ConstraintLayout
以固定且相等的长度并排放置两个按钮?
像这样的东西:
解决方案
试试这个代码..
<?xml version="1.0" encoding="utf-8"?>
<androidx.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/button1"
android:text="Button 1"
app:layout_constraintLeft_toLeftOf="parent"
android:textAllCaps="false"
app:layout_constraintRight_toLeftOf="@+id/guideline"
/>
<androidx.support.constraint.Guideline
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.5" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/button2"
android:text="Button 2"
android:textAllCaps="false"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toRightOf="@+id/guideline"
/>
</androidx.support.constraint.ConstraintLayout>
推荐阅读
- php - Inject Blade Array into script using HTML data attribute
- javascript - 即使承诺成功返回,DynamoDB 也没有删除该项目?
- php - 如何在一周内向同一个 ID 插入数据,但在下一周添加另一个 ID
- mysql - 在组合两个查询时多次重复相同的值
- twilio - 是否可以在 Twilio Studio 中连接流?
- java - Java 重新验证();将已重新定位的对象移回原始位置
- ruby-on-rails - 添加 jsonapi-suite 后获取`未初始化的常量 JsonapiCompliable::Adapters::ActiveRecord)`
- python - 安装 mply 库时出错。致命错误:gsl/gsl_sf.h:没有这样的文件或目录
- ios - 同一行上的多个标签具有相同的可拉伸宽度
- python - 使用 Pandas 的左连接表 (1:n),保持行数与左表相同