【问题标题】:Using dp for same dimension is not working for different phones of different resolutions but same dimention将 dp 用于相同尺寸不适用于不同分辨率但相同尺寸的不同手机
【发布时间】:2016-03-26 15:32:26
【问题描述】:

我正在开发一个必须支持所有尺寸的应用程序。由于 1920x1080 比 480x800 更宽,我无法同时为横向视图提供最适合的两者。因为它们位于同一维度下。纵向视图没有问题,因为纵向视图的差异确实很小,但是当将其转换为横向视图时,整个画面都不会出现。

这是 1920x1080 的视图。

这是 480x800 的视图

这两种尺寸都从 layout-sw320dp-land 访问它们的 xml 文件

我只在 hdp 屏幕上遇到这个问题,即 layout-sw320dp 屏幕,因为它的工作空间非常小。而且大屏幕也不存在这样的问题,因为我们有足够的空间来装饰。

谁能帮我解决这个问题?

对于这个问题,我们有很多问题和答案,但我无法找到完美的解决方案。

提前致谢。

【问题讨论】:

  • 让视图的 latout_height = "match_parent" 填满可用空间
  • 您是否尝试过“可用屏幕高度 hdp” 修饰符?
  • 不 @aelimill 我不知道你在说什么。
  • 和@pskink 我用的是centerVertical="true" 而不是height="math_parent"

标签: android responsive-design screen-orientation screen-resolution screen-size


【解决方案1】:

如果问题仅发生在此屏幕上,请考虑使用带权重的 LinearLayout,这将为您提供独立于屏幕尺寸或分辨率的响应式设计 - 相反,它将按百分比呈现,使视图占据相同百分比无论屏幕大小是多少。
附件是加权屏幕的 XML 示例。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="90"
        android:orientation="horizontal" >

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="90"
            android:background="#8000ff00"
            android:orientation="vertical" >

            <!-- This is the green view -->
        </LinearLayout>

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="10"
            android:background="#80ff0000"
            android:orientation="vertical" >
            <!-- This is the red view -->
        </LinearLayout>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="10"
        android:background="#800000ff" >

        <!-- This is the bottom blue view -->
    </LinearLayout>

</LinearLayout>

【讨论】:

  • 我在考虑视图的东西,但由于我是 android 的新手,我不知道如何完美地使用它。你能告诉我关于视图和百分比的基本概念吗?
  • 我添加了一些可能适合您需求的内容,您可以将带有颜色的线性布局切换为其他布局并使用它们的权重。有关更多信息,请参阅此帖子 - android.amberfog.com/?p=328
  • 对我有用的东西比完美。 layout-sw320dp-land-hdpilayout-sw320dpi-xhdpi
【解决方案2】:

这对我来说非常有用。 layout-sw320dp-land-hdpilayout-sw320dpi-land-xhdpi

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-09-07
    • 2020-12-26
    • 1970-01-01
    • 2014-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多