Выровняйте 2 вида снизу, но один будет опущен ниже - PullRequest
0 голосов
/ 29 октября 2018

Если у меня есть макет ограничения, подобный этому

<android.support.constraint.ConstraintLayout >
        <TextView
            android:layout_width="200dp"
            android:layout_height="50dp"
            android:text = "Some text"
           app:layout_constraintEnd_toEndOf="parent"
           app:layout_constraintStart_toStartOf="parent"
           app:layout_constraintBottom_toBottomOf="@+id/preview"
           app:layout_constraintTop_toTopOf="@+id/parent">

    />
    <Button
            android:layout_width="57dp"
            android:layout_height="281dp"
            app:layout_constraintBottom_toBottomOf="@+id/textview"
            app:layout_constraintEnd_toEndOf="@+id/textview"
            app:layout_constraintStart_toStartOf="@+id/textview">

    />
</android.support.constraint.ConstraintLayout> 

Где textview - другой виджет. тогда кнопка и нижние границы текстового представления будут выровнены.

Есть ли в любом случае, где я могу нажать кнопку на 10dp ниже? Поэтому я хочу, чтобы нижняя часть кнопки была прикреплена к нижней части текстового представления, однако я хотел, чтобы толчок был немного ниже на 10dp. Я пытался установить Android: layout_marginBottom = "- 10dp", но это не сработало! Есть идеи?

enter image description here

Ответы [ 3 ]

0 голосов
/ 29 октября 2018

Поместите их в FrameLayout с layout_height="wrap_content". Затем установите layout_gravity="bottom" в обоих дочерних представлениях. Дайте ваш TextView layout_marginBottom="10dp".

Результат должен быть примерно таким (это скелет только с соответствующими атрибутами):

<ConstraintLayout>
    <FrameLayout
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <TextView
            android:layout_marginBottom="10dp"
            android:layout_gravity="bottom"
        />
        <Button
            android:layout_gravity="bottom"
        />
    </FrameLayout>
</ConstraintLayout>
0 голосов
/ 31 октября 2018

в Java или Kotlin Seet textview.bringToFront ();

<?xml version="1.0" encoding="utf-8"?>
    <android.support.constraint.ConstraintLayout 
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        xmlns:app="http://schemas.android.com/apk/res-auto">


        <Button
            android:id="@+id/button"
            android:layout_width="157dp"
            android:layout_height="140dp"
            android:text="Button"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"/>

        <TextView
            android:id="@+id/textview"
            android:layout_width="150dp"
            android:layout_height="50dp"
            android:text = "Some text"
            android:gravity="center"
            android:textSize="15sp"
            android:textColor="#05afaf"
            app:layout_constraintBottom_toBottomOf="@id/button"
            app:layout_constraintStart_toStartOf="@id/button"
            app:layout_constraintEnd_toEndOf="@id/button"
            android:layout_marginBottom="20dp"
            />
    </android.support.constraint.ConstraintLayout>
0 голосов
/ 29 октября 2018

используйте android:layout_marginTop="10dp" в макете вашей кнопки

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...