android - 如何在 ConstraintLayout Android Studio 中创建重叠链

标签 android android-constraintlayout overlap

我想创建一个重叠链,它比其他元素保持所需的边距,并且它们可能有更多的元素彼此相邻。像这样:

最佳答案

这可以使用 Guidelines 来实现。尝试这样的事情:

<?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"
  android:layout_width="match_parent"
  android:layout_height="match_parent">

  <View
      android:id="@+id/view_1"
      android:layout_width="200dp"
      android:layout_height="200dp"
      android:background="#f00"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintStart_toStartOf="parent"
      app:layout_constraintTop_toTopOf="parent" />

  <android.support.constraint.Guideline
      android:id="@+id/guideline_1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:orientation="vertical"
      app:layout_constraintGuide_percent="0.26" />

  <View
      android:id="@+id/view_2"
      android:layout_width="200dp"
      android:layout_height="200dp"
      android:background="#0f0"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintStart_toEndOf="@id/guideline_1"
      app:layout_constraintTop_toTopOf="parent" />

  <android.support.constraint.Guideline
      android:id="@+id/guideline_2"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:orientation="vertical"
      app:layout_constraintGuide_percent="0.52" />

  <View
      android:id="@+id/view_3"
      android:layout_width="200dp"
      android:layout_height="200dp"
      android:background="#00f"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintStart_toEndOf="@id/guideline_2"
      app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

关于android - 如何在 ConstraintLayout Android Studio 中创建重叠链,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53877120/

相关文章:

r - 使用 ggplot2 在箱线图旁边创建垂直不重叠的标签

html - 防止我的固定页脚重叠内容

android 在屏幕关闭时保持 cpu 全速运行

Android Studio 2.2.3 Gradle Build 运行卡住

android - RecyclerView 适配器显示空白卡片 View

android - ConstraintLayout 编辑器添加了不必要的约束或边距,使其无法使用

javascript - Highcharts - 如何在重叠内容时强制 dataLabels 显示标签

Android HTTP 认证

android - 为通知膨胀约束布局时出错

android - android/kotlin 网格布局中单元格的高度和宽度相同