简体   繁体   English

在此示例中,如何在Textview2顶部放置TextView1?

[英]How in this example, can I have TextView1 on top of Textview2?

The image of what I need to acheive: 我需要达到的图像: 在此处输入图片说明

I have two FloatingActionButtons, 我有两个FloatingActionButtons
One constrainted to the left of the parent, 一个限制在父母的左边,
The other to the right, 右边的另一个

How to alter the following layout to achieve: 如何更改以下布局以实现:
Having 2 TextViews, both engagin all width available between buttons, and half of the height available, sitting on top of each other? 拥有2个TextView,它们既占据了按钮之间的所有可用宽度,又占据了可用高度的一半,彼此靠拢?

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


<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab_edit"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:backgroundTint="@color/colorPrimary"
    android:layout_marginTop="8dp"
    android:layout_marginBottom="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginEnd="8dp"
    app:fabSize="mini"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:srcCompat="@drawable/ic_edit_w"
    tools:layout_editor_absoluteX="41dp"
    tools:layout_editor_absoluteY="16dp" />

<TextView
    android:id="@+id/txt_top"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:padding="8dp"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintStart_toEndOf="@id/fab_edit"
    android:text="top"/>

<TextView
    android:id="@+id/txt_btm"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:padding="8dp"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toStartOf="@id/fab_play"
    android:text="bottom"/>

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab_play"
    android:layout_marginTop="8dp"
    android:layout_marginBottom="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginEnd="8dp"
    app:fabSize="mini"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:clickable="true"
    app:srcCompat="@drawable/ic_play_w"
    tools:layout_editor_absoluteX="220dp"
    tools:layout_editor_absoluteY="8dp" />

</android.support.constraint.ConstraintLayout>

Try the following: 请尝试以下操作:

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


<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab_edit"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:backgroundTint="@color/colorPrimary"
    android:layout_marginTop="8dp"
    android:layout_marginBottom="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginEnd="8dp"
    app:fabSize="mini"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    tools:layout_editor_absoluteX="41dp"
    tools:layout_editor_absoluteY="16dp" />

<TextView
    android:id="@+id/txt_top"
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:padding="8dp"
    android:gravity="center"
    app:layout_constraintBottom_toTopOf="@id/txt_btm"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintStart_toEndOf="@id/fab_edit"
    app:layout_constraintEnd_toStartOf="@id/fab_play"
    android:text="top"/>

<TextView
    android:id="@+id/txt_btm"
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:padding="8dp"
    android:gravity="center"
    app:layout_constraintTop_toBottomOf="@id/txt_top"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintStart_toEndOf="@id/fab_edit"
    app:layout_constraintEnd_toStartOf="@id/fab_play"
    android:text="bottom"/>

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab_play"
    android:layout_marginTop="8dp"
    android:layout_marginBottom="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginEnd="8dp"
    app:fabSize="mini"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:clickable="true"
    tools:layout_editor_absoluteX="220dp"
    tools:layout_editor_absoluteY="8dp" />

</android.support.constraint.ConstraintLayout>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM