Android ConstraintLayout-如何创建空间不均匀的链?

问题描述 投票:0回答:2

This is what i want to make

如何使用ConstraintLayouts创建它?我想在右侧附加一些视图,在左侧附加一些视图,中间的可变空间取决于右侧/左侧视图的长度。我知道链,但是它们总是在视图之间添加一个均匀的空间,我不想为该空间赋予固定的值。在线性布局中,我会做这样的事情:

<LinearLayout >
<ImageView />
<TextView />

<Space
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />

<ImageView />
<ImageView />
<TextView />
<LinearLayout/>

这可以在ConstraintLayout中复制吗?

java android android-constraintlayout
2个回答
1
投票

为什么直接将Constraints用于单个元素时,为什么需要在它们之间使用链或空格。请参阅此伪代码,这将有所帮助。

<androidx.constraintlayout.widget.ConstraintLayout
  .....
  .....
>
<TextView
  .....
  app:layout_constraintStart_toStartOf="parent"
  app:layout_constraintTop_toTopOf="parent"
  android:layout_marginStart="10dp"
  android:drawableStart=" Your clock icon" //Using this you don't have to use a separate ImageView
 />
 <ImageView
  .....
  app:layout_constraintEnd_toStartOf=" ID of your Download Count TextView"
  app:layout_constraintTop_toTopOf="parent"
  android:layout_marginEnd="10dp"
 />
 <TextView
  .....
  app:layout_constraintEnd_toEndOf="parent"
  app:layout_constraintTop_toTopOf="parent"
  android:layout_marginEnd="10dp"
  android:drawableStart=" Your Download icon"
 />
 </androidx.constraintlayout.widget.ConstraintLayout>

我已经使用drawbleStart而不是单独的ImageView,您可以根据需要使用它,只需使用app:layout_constraintEnd_toStartOf=" ID of the View"。给定的边距是屏幕结尾/开始与视图之间的间隔,您可以根据需要进行调整。

这将为您提供您共享的视图。检查是否有帮助。


0
投票

您可以使用ConstraintLayout这样实现:

<ConstraintLayout >

    <LinearLayout
        android:id="@+id/first"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:gravity="end"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@+id/first"
        app:layout_constraintTop_toTopOf="parent"/>

</ConstraintLayout>
© www.soinside.com 2019 - 2024. All rights reserved.