Android 定义“a”位置的准确方法是什么;“视图”;?

Android 定义“a”位置的准确方法是什么;“视图”;?,android,android-layout,user-interface,Android,Android Layout,User Interface,到目前为止,我尝试使用“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: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>

emulator和design preview的屏幕截图:


您可以使用“权重”属性或尝试使用ScrollView

您应该使用
约束布局
,但如果您不想做大的更改,您可以将最后一个
文本视图设置为具有
android:layout\u height=“0dp”
android:layout\u weight=“1”
因此它将使用所有剩余的
线性布局
,设置
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" />


干杯

我建议研究
ContrainLayout
。我认为在这种情况下,权重是更好的方法。在当前的情况下,权重属性可能有用,但如果版面中有任何输入字段,则应该使用scrollview而不是权重属性。谢谢