【问题标题】:how to change scalability in xml file如何更改 xml 文件中的可伸缩性
【发布时间】:2019-06-13 10:09:17
【问题描述】:

这是我的屏幕尺寸为 5.0 和 4.0 的应用。如何在任何地方以相同的方式更改比例。

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 android-layout scale screen-resolution android-calendar


    【解决方案1】:

    这是一个常见的问题。请阅读下面我从Android Developer Docs提取的内容

    确保您的布局灵活并适应不同的屏幕 尺寸,您应该使用“wrap_content”和“match_parent”作为宽度 和大多数视图组件的高度,而不是硬编码的尺寸。

    "wrap_content" 告诉视图将其大小设置为必要的大小 以适应该视图中的内容。

    "match_parent" 使视图在 父视图。

    例如:

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

    虽然这个视图的实际布局取决于其他属性 在其父视图和任何同级视图中,此 TextView 打算设置 它的宽度以填充所有可用空间(match_parent)并设置其 高度与文本长度所需的空间完全相同 (包装内容)。这允许视图适应不同的屏幕 大小和不同长度的文本。

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

    您可以通过创建额外的屏幕来提供特定于屏幕的布局 res/layout/ 目录——每个屏幕配置一个 需要不同的布局,然后附加屏幕配置 布局目录名称的限定符(例如 layout-w600dp 可用宽度为 600dp 的屏幕)。

    这些配置限定符代表可见的屏幕空间 可用于您的应用程序 UI。该系统考虑到任何系统 装饰(如导航栏)和窗口配置 更改(例如当用户启用多窗口模式时) 从您的应用中选择布局。

     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)
    

    【讨论】:

      猜你喜欢
      • 2013-12-11
      • 2012-03-06
      • 1970-01-01
      • 1970-01-01
      • 2018-10-21
      • 1970-01-01
      • 2018-10-03
      • 2012-07-22
      • 1970-01-01
      相关资源
      最近更新 更多