Как правильно разместить кнопки в относительном расположении - PullRequest
0 голосов
/ 10 апреля 2019

У меня есть относительное расположение, где добавлены некоторые текстовые представления. Они отображают данные из базы данных sqlite.

Я хочу разместить две кнопки, которые всегда будут располагаться ниже последнего результата.

Пожалуйста, проверьте изображения для большего понимания.

Вот код для дизайна:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="ID = "
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="#050505" />

    <TextView
        android:id="@+id/textViewID"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/textView1"
        android:layout_alignBottom="@+id/textView1"
        android:layout_toRightOf="@+id/textView1"
        android:text="UserID"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="#050505" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/textView1"
        android:text="Name = "
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="#050505" />

    <TextView
        android:id="@+id/textViewNAME"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textViewID"
        android:layout_toRightOf="@+id/textView2"
        android:text="Name"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="#050505" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/textView2"
        android:text="Nazov DVD = "
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="#050505" />

    <TextView
        android:id="@+id/textViewDvd"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/textView3"
        android:layout_toRightOf="@+id/textView3"
        android:text="phone number"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="#050505" />
</RelativeLayout>

Теперь отображается так:

screenshot-1

И я хочу отобразить две кнопки (кнопки редактирования и удаления), которые всегда будут отображаться ниже последнего результата, например:

screenshot-2

Я проверил другие статьи, но я действительно не знаю, как применить это к моему коду.

1 Ответ

0 голосов
/ 10 апреля 2019

Это можно сделать очень быстро с ConstraintLayout и направляющими .

Итак, вы сказали, что хотите, чтобы ваша кнопка была ниже последнего результата - используйте RecyclerView , чтобы показать ваш список результатов, поместите горизонтальную направляющую и дайте ему app:layout_constraintGuide_percent="0.your percent, чтобы вы могли решить , какой будет высота окна просмотра.

Вот пример:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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">

<Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="45dp"
    android:text="Edit"
    app:layout_constraintBottom_toBottomOf="@+id/button2"
    app:layout_constraintEnd_toStartOf="@+id/button2"
    app:layout_constraintHorizontal_bias="0.5"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="@+id/button2" />

<Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="8dp"
    android:layout_marginBottom="8dp"
    android:text="Delete"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.5"
    app:layout_constraintStart_toEndOf="@+id/button"
    app:layout_constraintTop_toBottomOf="@+id/recyclerView" />

<androidx.recyclerview.widget.RecyclerView
    android:id="@+id/recyclerView"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginBottom="8dp"
    android:background="@color/black"
    app:layout_constraintBottom_toTopOf="@+id/guideline3"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<androidx.constraintlayout.widget.Guideline
    android:id="@+id/guideline3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    app:layout_constraintGuide_percent="0.8" />

В конце это будет выглядеть так:

enter image description here

Теперь запомните, чтоэто всего лишь пример, и вы можете изменить его на внешний вид, цвет, размер, положение на экране и т. д.

...