如何更改 xml 文件中的可伸缩性

how to change scalability in xml file

这是我的应用程序,屏幕尺寸为 5.0 和 4。0.How我可以在任何地方以相同的方式更改比例吗?

5.0

4.0

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/background"
    android:orientation="vertical">


    <TextView
        android:id="@+id/tv_sprawdz"
        android:layout_width="match_parent"
        android:layout_height="225dp"
        android:layout_marginTop="15dp"
        android:gravity="center_horizontal"
        android:text="Wybierz dzień"
        android:textAlignment="center"
        android:textColor="@color/White"
        android:textSize="18sp"
        android:textStyle="italic" />


    <LinearLayout

        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="15dp"
        android:background="@drawable/bg_celen">

        <CalendarView

            android:id="@+id/calendarView"
            android:layout_width="350dp"
            android:layout_height="537dp">

        </CalendarView>
    </LinearLayout>

</LinearLayout>

这是一个常见问题。请阅读下面我从 Android Developer Docs

中提取的内容

To ensure that your layout is flexible and adapts to different screen sizes, you should use "wrap_content" and "match_parent" for the width and height of most view components, instead of hard-coded sizes.

"wrap_content" tells the view to set its size to whatever is necessary to fit the content within that view.

"match_parent" makes the view expand to as much as possible within the parent view.

For example:

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/lorem_ipsum" />

Although the actual layout for this view depends on other attributes in its parent view and any sibling views, this TextView intends to set its width to fill all available space (match_parent) and set its height to exactly as much space is required by the length of the text (wrap_content). This allows the view to adapt to different screen sizes and different lengths of text.

此外,您还可以针对不同的屏幕尺寸使用不同的布局,如下所述。

You can provide screen-specific layouts by creating additional res/layout/ directories—one for each screen configuration that requires a different layout—and then append a screen configuration qualifier to the layout directory name (such as layout-w600dp for screens that have 600dp of available width).

These configuration qualifiers represent the visible screen space available for your app UI. The system takes into account any system decorations (such as the navigation bar) and window configuration changes (such as when the user enables multi-window mode) when selecting the layout from your app.

 res/layout/main_activity.xml # For handsets (smaller than 600dp available Width) 
 res/layout-w600dp/main_activity.xml # For 7” tablets
 or any screen with 600dp # available width (possibly landscape handsets)