簡體   English   中英

如何在沒有太多代碼更改的情況下使相對布局應用程序具有響應性?

[英]How to make a relative Layout app responsive without too many code changes?

我有一個相對布局的應用程序,里面有:

1) 具有一個 switch 和 2 個editText垂直線性布局。

2) 垂直布局下方的水平線性布局,帶有 2 個按鈕。

它在editText A8 手機上運行良好,但水平線性布局在較小屏幕手機上的底部editText上重疊。

我需要一些關於如何在沒有太多代碼更改的情況下使其具有響應性的指導,因為我的界面設計技術非常差。

謝謝你的幫助。

我試圖將其轉換為Constraint-Layout但它使我的用戶界面變得更糟。 該應用程序停止響應。

<?xml version="1.0" encoding="utf-8"?>
<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"
    android:orientation="vertical"
    tools:context=".MainActivity"
    android:animateLayoutChanges="true"
    android:clipChildren="false">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:padding="15dp">

        <Switch
            android:id="@+id/switch1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:text="French to English"
            android:textSize="18sp"
            android:checked="true"
            android:thumbTint="@color/colorPrimary"
            android:trackTint="@color/colorAccent" />

        <EditText
            android:id="@+id/pname"
            android:layout_width="match_parent"
            android:layout_height="225dp"
            android:layout_marginTop="15dp"
            android:maxLength="100"
            android:background="@drawable/rounded_border_edittext"
            android:ems="15"
            android:gravity="top"
            android:hint="Enter your text to translate here..."
            android:inputType="textMultiLine"
            android:padding="10dp" />

        <EditText
            android:id="@+id/target"
            android:layout_width="match_parent"
            android:layout_height="225dp"
            android:layout_marginTop="30dp"
            android:maxLength="100"
            android:background="@drawable/rounded_border_edittext1"
            android:ems="15"
            android:gravity="top"
            android:hint="Your translated text will appear here..."
            android:inputType="textMultiLine"
            android:padding="10dp" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal"
        android:padding="15dp">

        <Button
            android:id="@+id/btnsave"
            style="@style/Widget.AppCompat.Button.Colored"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Save" />

        <Button
            android:id="@+id/btntranslate"
            style="@style/Widget.AppCompat.Button.Colored"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Translate" />
    </LinearLayout>
</RelativeLayout>

嘗試將垂直 LinearLayout 中的兩個 EditText 的高度設置為 190dp

android:layout_height="190dp"

以及他們的 margingTop 值到 15dp

android:layout_marginTop="15dp"

這將適合 Android 設備的最小屏幕尺寸,即 426x320

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM