【问题标题】:App Layout changes with change in screen size应用布局随着屏幕大小的变化而变化
【发布时间】:2013-12-06 15:46:24
【问题描述】:

我正在用 android 开发一个图表应用程序。 我已经在 dp 中设置了所有布局参数,但我仍然面临不同屏幕尺寸的对齐问题..

例如,与正常的 4 英寸屏幕相比,我的登录按钮或图表的屏幕尺寸更大。

这是操作系统版本的错误还是我们需要为每种类型的屏幕尺寸设置参数。

两个不同手机中相同登录屏幕的屏幕截图

【问题讨论】:

  • 可以分享截图吗?

标签: android layout screen


【解决方案1】:

为避免此类问题,请将按钮、文本字段等与屏幕边缘对齐,例如

// for aligning it to the left of screen
        android:layout_alignParentLeft="true"
// for aligning it to the right of screen
        android:layout_alignParentRight="true"
// for aligning it to the Bottom of screen
        android:layout_alignParentBottom="true"

那么你的小部件不会改变屏幕底部、右侧或左侧的原始位置

别忘了给答案投票:)

【讨论】:

    【解决方案2】:

    使用相对布局作为主要布局。并在其中添加一个 LinearLayout 布局。这是您的登录框的容器。使用 android:layout_centerInParent="true" 将对齐设置为居中。在此容器内添加您的登录框。

        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            android:id="@+id/RelativeLayout1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            tools:context=".MainActivity" >
    
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:orientation="vertical" >
    
        </LinearLayout>
    
        </RelativeLayout >
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-15
      • 1970-01-01
      • 2016-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多