Lan*_*tka 6 layout android android-layout android-constraintlayout
我想用 ConstraintLayout 做这个布局。
我所做的是添加 3 个 TextViews 1,2 和 3(粉红色)将它们连接到父级的左侧,并告诉它们在另一个之下。有用。
然后我需要添加视图 4 和 5,以便它们始终位于 2 和 3 的右侧,并且其内容必须垂直对齐到左边缘,如图所示。
当我添加时的问题
app:layout_constraintLeft_toRightOf="2 OR 3"
Run Code Online (Sandbox Code Playgroud)
4 和 5 中的文本未正确对齐。我明白了
当我使用指南时,我得到了这个
app:layout_constraintLeft_toRightOf="@id/guideline"
Run Code Online (Sandbox Code Playgroud)
有谁知道什么可以帮助解决这个问题?
编辑。第一次尝试的PS布局
<android.support.constraint.ConstraintLayout
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="match_parent"
android:padding="16dp"
android:id="@+id/constraintLayout"
>
<TextView
android:id="@+id/instrument_name"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:text="AUDUSD"
app:layout_constraintStart_toStartOf="@+id/constraintLayout"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"/>
<TextView
android:id="@+id/trade_action_label"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="BUYjhkjhkjhvg"
app:layout_constraintStart_toStartOf="@+id/instrument_name"
app:layout_constraintTop_toBottomOf="@id/instrument_name"
tools:layout_editor_absoluteX="16dp"
android:layout_marginTop="1dp"/>
<TextView
android:id="@+id/net_pl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Net p/l"
app:layout_constraintStart_toStartOf="@+id/trade_action_label"
app:layout_constraintTop_toBottomOf="@id/trade_action_label"/>
<TextView
android:id="@+id/record_amount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="123"
app:layout_constraintTop_toTopOf="@id/trade_action_label"
app:layout_constraintLeft_toRightOf="@id/trade_action_label"
tools:layout_editor_absoluteY="33dp"
/>
<TextView
android:id="@+id/pl_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="12"
app:layout_constraintTop_toTopOf="@id/net_pl"
app:layout_constraintLeft_toRightOf="@id/net_pl"/>
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
您可以使用 aBarrier来复制 的行为TableLayout。
<?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/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:text="@string/warehouse"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:text="@string/hospital"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView1" />
<android.support.constraint.Barrier
android:id="@+id/barrier7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="end"
app:constraint_referenced_ids="textView2,textView1" />
<TextView
android:id="@+id/textView3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="@string/lorem_ipsum"
app:layout_constraintStart_toEndOf="@+id/barrier7"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
更多信息请参见: https: //constraintlayout.com/basics/barriers.html
我仔细看看你想做什么。我认为您需要考虑在您的ConstraintLayout. 请参阅此处的文档。
确保您使用ConstraintLayout实现链的版本。
更新
这是您正在尝试执行的操作的示例。我已经简化了您的布局,以更好地展示什么是有效的。注意 box1<->box2 和 box3<->box4 的交叉链接。这些链接建立了链条。
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="81dp">
<TextView
android:id="@+id/box1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:layout_marginTop="16dp"
android:text="Text box 1 xxxxxxx"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/box2"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@id/box2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:layout_marginTop="0dp"
android:text="Text box 2 yyyyyyyyyy"
app:layout_constraintLeft_toRightOf="@id/box1"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="@id/box1" />
<TextView
android:id="@+id/box3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:layout_marginTop="0dp"
android:text="Text box 3 zzzz"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/box4"
app:layout_constraintTop_toBottomOf="@id/box1" />
<TextView
android:id="@id/box4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:layout_marginTop="0dp"
android:text="Text box 4"
app:layout_constraintLeft_toRightOf="@id/box3"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="@id/box3" />
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
用于app:layout_constraintHorizontal_weight影响每个视图获得多少空间。
| 归档时间: |
|
| 查看次数: |
9670 次 |
| 最近记录: |