如何为所有屏幕尺寸优化布局?

时间:2019-08-22 20:59:51

标签: android xml android-layout screen android-screen-support

我对XML没有太多的经验。我几天以来一直在尝试针对所有屏幕尺寸优化布局。我看到此XML不适用于较小或较大的屏幕。我如何在所有屏幕上都适合呢?

Screenshot

[<RelativeLayout 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"
    tools:context=".MainActivity">


    <androidx.constraintlayout.widget.ConstraintLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:gravity="center"
            android:orientation="vertical"
            android:paddingTop="30dp"
            app:layout_constraintEnd_toStartOf="@+id/linearLayout"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">

            <ImageView
                android:layout_width="200dp"
                android:layout_height="200dp"
                android:layout_marginTop="10dp"
                android:scaleType="fitCenter"
                android:src="@drawable/baccologo" />

            <TextView
                android:layout_width="300dp"
                android:layout_height="wrap_content"
                android:fontFamily="@font/leckerli_one"
                android:gravity="center"
                android:text="@string/welcome"
                android:textColor="@android:color/white"
                android:textSize="45sp"
                android:textStyle="bold"
                tools:fontFamily="@font/leckerli_one"
                tools:textColor="@android:color/background_light" />


            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:fontFamily="@font/leckerli_one"
                android:gravity="center"
                android:text="txt1"
                android:textColor="@color/fbutton_color_carrot"
                android:textSize="45sp"
                android:textStyle="bold"
                android:transformPivotY="20dp" />


            <View
                android:layout_width="160dp"
                android:layout_height="5dp"
                android:background="@color/white"></View>

            <TextView
                android:layout_width="300dp"
                android:layout_height="wrap_content"
                android:fontFamily="@font/leckerli_one"
                android:gravity="center"
                android:text="txt2"
                android:textColor="@color/colorText"
                android:textSize="30sp"
                android:textStyle="bold" />



            <View
                android:layout_width="160dp"
                android:layout_height="5dp"
                android:background="@color/white"></View>


        </LinearLayout>


        <LinearLayout
            android:id="@+id/linearLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentBottom="true"
            android:gravity="bottom|center_horizontal|center_vertical"
            android:orientation="vertical">

            <info.hoang8f.widget.FButton
                android:id="@+id/btn_register"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="8dp"
                android:layout_marginRight="8dp"
                android:hapticFeedbackEnabled="true"
                android:text="login/register"
                android:textColor="@color/white"
                app:cornerRadius="4dp"
                app:fButtonColor="#00CA4E"
                app:shadowColor="@android:color/black"
                app:shadowEnabled="true"
                app:shadowHeight="5dp" />

            <info.hoang8f.widget.FButton
                android:id="@+id/btn_call_us"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="8dp"
                android:layout_marginTop="4dp"
                android:layout_marginRight="8dp"
                android:hapticFeedbackEnabled="true"
                android:text="rufen sie uns an!"
                android:textColor="@color/white"
                app:cornerRadius="4dp"
                app:fButtonColor="#FFBD44"
                app:shadowColor="@android:color/black"
                app:shadowEnabled="true"
                app:shadowHeight="5dp" />

            <info.hoang8f.widget.FButton
                android:id="@+id/btn_navigate_map"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="8dp"
                android:layout_marginTop="4dp"
                android:layout_marginRight="8dp"
                android:hapticFeedbackEnabled="true"
                android:text="Der Weg zu uns"
                android:textColor="@color/white"
                app:cornerRadius="4dp"
                app:fButtonColor="#FF605C"
                app:shadowColor="@android:color/black"
                app:shadowEnabled="true"
                app:shadowHeight="5dp" />

        </LinearLayout>


    </androidx.constraintlayout.widget.ConstraintLayout>][1]

0 个答案:

没有答案