Размещение кнопки над двумя разными LinearLayouts - PullRequest
0 голосов
/ 16 января 2019

Итак, я хотел бы добавить кнопку с текстом «Уже зарегистрированы?» на среднем нижнем экране, но мой код содержит два разных LinearLayouts для половины левой и половины правой стороны. Я хочу, чтобы кнопка была наполовину линейной, а наполовину справа. Кроме того, они кликабельны, поэтому, насколько я понимаю, они должны быть в моем текущем макете, а не включать их.

что у меня сейчас есть:

enter image description here

Что я хочу получить:

enter image description here

мой код

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:baselineAligned="false"
    tools:context=".MainActivity"
    android:weightSum="2"
    android:orientation="horizontal">

    <LinearLayout
        android:id="@+id/customerLinearLayout"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_weight="1"
        android:background="@color/lightblueMainActivity"
        android:onClick="customerSignUp">

        <TextView
            android:layout_gravity="center_vertical"
            android:gravity="center"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="24sp"
            android:textColor="@color/orangeMainActivity"
            android:text="@string/customerMainActivity"/>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/electricianLinearLayout"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_weight="1"
        android:background="@color/orangeMainActivity"
        android:onClick="electricianSignUp">

        <TextView
            android:layout_gravity="center_vertical"
            android:gravity="center"
            android:textSize="24sp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textColor="@color/lightblueMainActivity"
            android:text="@string/electricianMainActivity"/>
    </LinearLayout>
</LinearLayout>

СПАСИБО ЗА ПРЕДЕЛА!

1 Ответ

0 голосов
/ 16 января 2019

Существуют и другие типы ViewGroup, кроме LinearLayout, которые позволяют вам получить эффект «разделенного экрана», но давайте сделаем его простым и используем взвешенный LinearLayout для разделения экрана.

Дочерние элементы View s, однако, могут иметь значение TextView s (промежуточные значения ViewGroup не требуются), поскольку вы можете позволить им иметь цвет фона, а также управлять выравниванием текста.

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

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:weightSum="2">
        <TextView
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent"
            android:text="Customer"
            android:textColor="#aaaaaa"
            android:textSize="20sp"
            android:gravity="center"
            android:background="#0000ff"/>
        <TextView
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent"
            android:text="Electrician"
            android:textColor="#666666"
            android:textSize="20sp"
            android:gravity="center"
            android:background="#ffab00"/>
    </LinearLayout>
    <TextView android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal|bottom"
        android:layout_marginBottom="24dp"
        android:textColor="#ffffff"
        android:textSize="20sp"
        android:text="Already Registered?"/>
</FrameLayout>

enter image description here

...