【问题标题】:android normal layout screen not applicable to all normal screenandroid正常布局屏幕不适用于所有正常屏幕
【发布时间】:2014-06-08 03:22:36
【问题描述】:

我在布局文件夹中创建了 android 布局,我的设备英寸为 3.2 到 5 英寸,属于普通屏幕,仅针对此设备,但我的布局在 3.2 英寸和 4 英寸方面彼此不同。

【问题讨论】:

    标签: android layout screen between difference


    【解决方案1】:

    您可以在 java 中获取屏幕大小问题并进行检查

    【讨论】:

    • 我只针对普通屏幕而不是小,大,它们将只是普通屏幕...在线性布局 3.2 和 4 英寸中使用 webview、图像和谷歌广告仅在普通屏幕下
    【解决方案2】:
    res/layout/my_layout.xml             // layout for normal screen size ("default")
    res/layout-small/my_layout.xml       // layout for small screen size
    res/layout-large/my_layout.xml       // layout for large screen size
    res/layout-xlarge/my_layout.xml      // layout for extra large screen size
    res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation
    
    res/drawable-mdpi/my_icon.png        // bitmap for medium density
    res/drawable-hdpi/my_icon.png        // bitmap for high density
    res/drawable-xhdpi/my_icon.png       // bitmap for extra high density
    

    【讨论】:

    • res/layout/my_layout.xml // 正常屏幕尺寸的布局(“默认”)我只使用这个布局,希望支持从 3.2 英寸到 4.7 英寸的相互对齐变化
    【解决方案3】:

    关注:Supporting multiple screen size - Android

    像这样定义你的维度值

    res/values-sw600dp/dimen.xml -> 7+ inches
    res/values-sw720dp/dimen.xml -> 10+ inches
    values-w360dp
    values-w500dp
    values-w480dp
    values-xlarge
    values-v11
    values-v14
    

    Sherlock Bar检查那里

    【讨论】:

    • 你能给我一些链接吗
    • res/layout/my_layout.xml // 正常屏幕尺寸的布局(“默认”)...在 3.2 到 4.7 英寸之间仅属于正常默认布局..我正在使用 imageview、webview、谷歌添加线性布局
    【解决方案4】:

    您需要为此创建不同的文件夹

    例如

    布局文件夹/main.xml

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/RelativeLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/background"
    android:orientation="vertical" >
    
    <Button
        android:id="@+id/rate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="Rate us"
        android:textColor="@color/black_font" />
    
    </RelativeLayout>
    

    layout-large/main.xml

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/RelativeLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/background"
    android:orientation="vertical" >
    
    <Button
        android:id="@+id/rate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="Rate us"
        android:textColor="@color/black_font"
        android:textSize="30sp" />
    
    </RelativeLayout>
    

    layout-xlarge/main.xml

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/RelativeLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/background"
    android:orientation="vertical" >
    
    <Button
        android:id="@+id/rate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="Rate us"
        android:textColor="@color/black_font"
        android:textSize="60sp" />
    
    </RelativeLayout>
    

    欲了解更多信息,请参阅this link

    对于您的问题,您需要按 Density 创建它

    1. ldpi 用于低密度 (ldpi) 屏幕 (~120dpi) 的资源。
    2. mdpi 中等密度 (mdpi) 屏幕 (~160dpi) 的资源。 (这是基线密度。)
    3. hdpi 用于高密度 (hdpi) 屏幕 (~240dpi) 的资源。
    4. xhdpi 超高密度 (xhdpi) 屏幕 (~320dpi) 的资源。
    5. nodpi 适用于所有密度的资源。这些是与密度无关的资源。无论当前屏幕的密度如何,系统都不会缩放带有此限定符标记的资源。
    6. tvdpi mdpi 和 hdpi 之间的屏幕资源;大约 213dpi。这不被视为“主要”密度组。它主要用于电视,大多数应用程序不需要它 - 为大多数应用程序提供 mdpi 和 hdpi 资源就足够了,系统将根据需要对其进行缩放。如果您认为有必要提供 tvdpi 资源,则应将它们的大小调整为 1.33*mdpi。例如,用于 mdpi 屏幕的 100px x 100px 图像对于 tvdpi 应该是 133px x 133px。

    【讨论】:

    • res/layout/my_layout.xml // 正常屏幕尺寸的布局(“默认”)...在 3.2 到 4.7 英寸之间仅属于正常默认布局..我正在使用 imageview、webview、谷歌添加线性布局
    猜你喜欢
    • 1970-01-01
    • 2017-07-05
    • 2021-12-15
    • 1970-01-01
    • 2017-02-16
    • 2015-12-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-11
    相关资源
    最近更新 更多