Android:更改设备设置时的布局尺寸问题 [英] Android: layout size issue when changing device settings

查看:46
本文介绍了Android:更改设备设置时的布局尺寸问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在尺寸更改方面遇到麻烦.

I am currently facing a trouble regarding size change.

我已经使用dp对xml文件进行了编码,但是当我更改设备屏幕尺寸时,布局也会改变.

I have coded my xml files using dp's, but when I change the device screen size, the layout would change.

例如,当我进入设置"-显示"-屏幕缩放和字体"并将屏幕缩放"从中"设置为大"时,布局中的某些元素(例如imageview或button)将增长并超出屏幕.

For example, when I go into Settings - Display - Screen zoom and font and set screen zoom from medium to large, some of the elements in my layout such as imageview or button would grow and go beyond the screen.

由于我使用的是包含LinearLayouts和FrameLayouts的复杂布局,因此我不清楚如何在其他任何设备或屏幕尺寸下使该布局看起来都不错.好像我更改屏幕缩放设置时,dp的值改变了.

Since I'm using a complex layout containing LinearLayouts and FrameLayouts, I am not clear about how I should make this layout look alright in any other devices or screen sizes. It seems like when I change the screen zoom setting, the value of dp changes.

是否可以避免此问题,或者可以通过编程方式将屏幕缩放设置设置为中级?

Is there a way to avoid this problem, or maybe to programmatically set screen zoom setting to medium?

这是我的代码:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:gravity="center"
    android:layout_gravity="center"
    android:layout_marginTop="65dp">

    <android.support.constraint.ConstraintLayout
        android:id="@+id/frameLayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="95dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.3">

        <ImageView
            android:id="@+id/imageView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/home_map" />

        <Button
            android:id="@+id/pick1"
            android:layout_width="34dp"
            android:layout_height="56dp"
            android:background="@drawable/top_deselected"
            app:layout_constraintBottom_toBottomOf="@+id/imageView"
            app:layout_constraintEnd_toEndOf="@+id/imageView"
            app:layout_constraintHorizontal_bias="0.17"
            app:layout_constraintStart_toStartOf="@+id/imageView"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.18" />

        <Button
            android:id="@+id/pick2"
            android:layout_width="34dp"
            android:layout_height="56dp"
            android:background="@drawable/jungle_deselected"
            app:layout_constraintBottom_toBottomOf="@+id/imageView"
            app:layout_constraintEnd_toEndOf="@+id/imageView"
            app:layout_constraintHorizontal_bias="0.28"
            app:layout_constraintStart_toStartOf="@+id/imageView"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.367" />

        <Button
            android:id="@+id/pick3"
            android:layout_width="34dp"
            android:layout_height="56dp"
            android:background="@drawable/mid_deselected"
            app:layout_constraintBottom_toBottomOf="@+id/imageView"
            app:layout_constraintEnd_toEndOf="@+id/imageView"
            app:layout_constraintHorizontal_bias="0.424"
            app:layout_constraintStart_toStartOf="@+id/imageView"
            app:layout_constraintTop_toTopOf="@+id/imageView"
            app:layout_constraintVertical_bias="0.43" />

        <Button
            android:id="@+id/pick4"
            android:layout_width="34dp"
            android:layout_height="56dp"
            android:background="@drawable/support_deselected"
            app:layout_constraintBottom_toBottomOf="@+id/imageView"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.615"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="@+id/imageView"
            app:layout_constraintVertical_bias="0.71" />

        <Button
            android:id="@+id/pick5"
            android:layout_width="34dp"
            android:layout_height="56dp"
            android:background="@drawable/adc_deselected"
            app:layout_constraintBottom_toBottomOf="@+id/imageView"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.733"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="@+id/imageView"
            app:layout_constraintVertical_bias="0.71" />

    </android.support.constraint.ConstraintLayout>

    <Button
        android:layout_width="335dp"
        android:layout_height="42.5dp"
        android:layout_marginBottom="5.5dp"
        android:background="@drawable/home_mode"
        android:id="@+id/home_mode"/>

    <Button
        android:layout_width="335dp"
        android:layout_height="42.5dp"
        android:background="@drawable/home_match"
        android:id="@+id/home_match"/>

</LinearLayout>

约束布局以前是框架布局,但我现在正在尝试约束布局.

The constraint layout used to be a frame layout, but I was just now trying out the constraint layout.

推荐答案

您还可以使用此库,该库可在所有设备上使用,而无需制作任何dimen文件.但仅将其用于小部件的大小,对于文本大小仅使用"sp".

You can also use this library, it is working on all devices, no need to make any dimen file and all. but use this only for the size of widgets, for text size use "sp" only.

https://github.com/intuit/sdp

这篇关于Android:更改设备设置时的布局尺寸问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆