@Aksen_BY

Как размещать элементы приложения из центра?

Центрирую форму ввода текста и пытаюсь разместить еще одну форму снизу и одну сверху. Но они съезжают вверх, в чем проблема?
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    android:scrollbars="vertical" >

    <RelativeLayout xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="640dp"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context=".activity.MainActivity"
        android:background="#ffffff">


        <EditText
            android:layout_width="300dp"
            android:layout_height="wrap_content"
            android:id="@+id/editText"
            android:layout_centerVertical="true"
            android:layout_centerHorizontal="true" />

        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/editText2"
            android:layout_below="@+id/editText"
            android:layout_marginTop="70dp"
            android:layout_alignLeft="@+id/editText"
            android:layout_alignStart="@+id/editText"
            android:layout_alignRight="@+id/editText"
            android:layout_alignEnd="@+id/editText" />

        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/editText3"
            android:layout_above="@+id/editText"
            android:layout_marginTop="70dp"
            android:layout_alignLeft="@+id/editText2"
            android:layout_alignStart="@+id/editText2"
            android:layout_alignRight="@+id/editText2"
            android:layout_alignEnd="@+id/editText2" />
    </RelativeLayout>

</ScrollView>

78f86a83609c4d1ba8a820452c6a2e1e.jpg
  • Вопрос задан
  • 347 просмотров
Решения вопроса 1
@Dekker8
Если три EditText поставить по центру то получилось у меня так....

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.centeractivity.MainActivity" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:orientation="vertical" >

        <EditText
            android:id="@+id/editText1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10" >

            <requestFocus />
        </EditText>

        <EditText
            android:id="@+id/editText3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10" />

        <EditText
            android:id="@+id/editText2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10" />

    </LinearLayout>
</RelativeLayout>
Ответ написан
Пригласить эксперта
Ответы на вопрос 1
zagayevskiy
@zagayevskiy Куратор тега Android
Android developer at Yandex
Вас спасёт LinearLayout с orientation=vertical и gravity=center
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы