android-layout - 我无法均匀间隔按钮
问题描述
我在android studio中使用约束布局,我想在主要活动上均匀间隔按钮,它在移动视图上工作正常,但是当我尝试切换到平板电脑视图时它变得一团糟,有没有办法在两者上均匀间隔按钮意见?这是图像中的问题
解决方案
如果您想了解如何使用 chainStyle 的示例,可以查看我们的一个公共示例。或者这是链接中的粘贴:
<androidx.cardview.widget.CardView
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="wrap_content"
android:layout_margin="@dimen/margin_std_half"
android:clickable="true"
app:cardBackgroundColor="@color/colorAccentLighter"
app:cardCornerRadius="@dimen/cardview_corner_radius"
app:contentPadding="@dimen/cardview_padding"
>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/sku_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="@id/guideline"
app:layout_constraintEnd_toStartOf="@id/sku_price"
app:layout_constraintHorizontal_chainStyle="spread_inside"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="This is a Title placeholder"/>
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/sku_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="@id/guideline"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/sku_title"
app:layout_constraintTop_toTopOf="parent"
tools:text="$4.99"/>
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline"
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.25"/>
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/sku_image"
android:layout_width="wrap_content"
android:layout_height="68dp"
android:adjustViewBounds="true"
android:maxWidth="126dp"
android:scaleType="centerInside"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/sku_description"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@id/guideline"
/>
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/sku_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin_std_half"
android:layout_marginRight="@dimen/margin_std_half"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/sku_image"
app:layout_constraintTop_toTopOf="@id/guideline"
tools:text="This is a description placeholder, telling users how cool this item is"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
推荐阅读
- amazon-web-services - AWS Cost Explorer API:与仪表板值不匹配
- javascript - Fetch DELETE 方法在 URL 中添加 unicode 字符
- javascript - Jupyter Lab 中显示的 HTML 报告需要 JavaScript
- c++ - 无法在 Qt Creator 环境中运行程序
- sql - 在选定的 row_to_json 结果上嵌套循环
- html - 如何使用 Flutter 解析 div 内容?
- javascript - 未捕获的 SyntaxError:JSON.parse 处的 JSON 输入意外结束(
) 在 XMLHttpRequest.r.onreadystatechange (app.js:115) - sass - 使用 sass 和 scss 编译 css 文件 - 按使用/导入顺序编译
- android - SQLite 选择实际 7 天(周)过去的数据,如果不存在,则为空/零
- c++ - 为什么在 C++ 中同时访问两个联合成员有效