android - 使用 ConstraintLayout 并排放置 2 个 View

标签 android android-constraintlayout

<分区>

我试图在 ConstraintLayout 中并排放置 2 个 textView,而左 View 有一个动态文本(可以是短文本,也可以是很长的文本,如果它与第二个 View 重叠,则应该是省略号)。 我希望 2 个 TextView 并排放置,因此第二个 View 将从第一个 View 的末尾开始。

请帮忙:-)

最佳答案

虽然这是最简单的一种,但如果你想让它们占据相同的空间,那么你可以使用layout_constraintVertical_chainStyle。

 <?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">

 <TextView
    android:id="@+id/text_view1"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:text="Random 1"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<TextView
    android:id="@+id/text_view2"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:text="Random 1"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toEndOf="@+id/text_view1"
    app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>

看看这个 https://medium.com/@loutry/guide-to-constraintlayout-407cd87bc013 .ChainStyle 通常在您希望它们水平或垂直均匀分布时使用。链由链的第一个元素(链的“头”)上设置的属性控制,这是水平链最左边的小部件,以及垂直链的最顶层小部件。

关于android - 使用 ConstraintLayout 并排放置 2 个 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56562782/

相关文章:

android - ConstraintLayout - 让元素占用必要的空间直到可用空间

Android - 调整动态创建的 UI 小部件

android - 在一个 jar 库中支持不同的 Android 版本

android - 在android中绘制斜矩形

android - 以编程方式更改约束布局中的高度?

java - 联系人页面 - 使用列表或使用标准 View 构建布局

android - 将布局滑动到屏幕中间(向上滑动),然后向上或向下滑动

android - 在android中自动清除应用程序更新时的用户缓存

android - 动态更改 src 后保存 Android 图像状态

android - 在水平 ScrollView 内创建水平 ScrollView