Каков точный способ определить положение «ВИДА»? - PullRequest
0 голосов
/ 07 октября 2019

Я пытался определить, где будет располагаться представление, используя «android: layout_marginTop», что в то время казалось более простым, но теперь я обнаружил серьезные проблемы с ним. самый нижний вид не отображается на маленьких экранах.

вот мой XML-код

<?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:layout_gravity="center"
    android:orientation="vertical"
    tools:context=".StartActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="250dp"
        android:background="#6CD9CE">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:adjustViewBounds="true"
            android:scaleType="fitCenter"
            android:scaleX="1.0"
            android:scaleY="1.0"
            android:src="@drawable/logo_transparent" />


    </LinearLayout>


    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Welcome."
        android:textAlignment="center"
        android:layout_gravity="center"
        android:layout_marginTop="50dp"
        android:textSize="20sp"
        android:textStyle="bold"/>


    <Button
        android:layout_width="350dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:background="#ffffff"
        android:backgroundTint="#6CD9CE"
        android:layout_marginTop="60dp"
        android:text="Login"
        android:textColor="@color/white"/>


    <Button
        android:layout_width="350dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:background="#6CD9CE"
        android:layout_marginTop="50dp"
        android:text="Register"
        android:textColor="@color/white"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="RandomText"
        android:textSize="20sp"
        android:layout_gravity="center"
        android:layout_marginTop="200dp"/>



</LinearLayout>

Снимок экрана из эмулятора и предварительный просмотр дизайна:

Предварительный просмотр дизайна

Эмулятор

Ответы [ 2 ]

1 голос
/ 07 октября 2019

Вы можете использовать атрибут 'weight' или попробовать ScrollView

0 голосов
/ 07 октября 2019

Вы должны использовать ContraintLayout, но если вы не хотите вносить большие изменения, вы можете установить последние TextView, чтобы иметь android:layout_height="0dp" и android:layout_weight="1", так что это займет все остальные LinearLayout, установите android:gravity="bottom", а затем немного расположите снизу с помощью android:paddingBottom="20dp"

Примерно так:

<TextView
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:layout_gravity="center"
        android:gravity="bottom"
        android:paddingBottom="20dp"
        android:text="RandomText"
        android:textSize="20sp" />

Приветствия

...