【问题标题】:Prevent Android UI scaling防止 Android UI 缩放
【发布时间】:2011-04-09 14:36:00
【问题描述】:

基本上,我在线性布局中有一系列图像视图。我已将每个 imageviews 布局宽度和布局高度属性分别设置为 100dp 和 50dp(我也尝试过 px 而不是 dp,并且我尝试过更改 imageviews 最大尺寸)但 imageviews 继续缩放而不是停留在这个固定大小。

我只是想知道是否有人知道我做错了什么?

XML:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
        android:orientation="vertical" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:background="@drawable/backgroundtop" android:gravity="bottom">
    <FrameLayout android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/frameLayout1">
        <ImageView android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/imageView3" android:src="@drawable/base" android:layout_gravity="center"></ImageView>
        <LinearLayout android:id="@+id/linearLayout1" android:layout_height="wrap_content" android:orientation="vertical" android:gravity="center" android:paddingTop="50px" android:layout_width="match_parent">
            <ImageView android:src="@drawable/buttonnews" android:id="@+id/imageView1" android:layout_width="123dp" android:layout_height="49dp" android:scaleType="center"></ImageView>
            <ImageView android:id="@+id/imageView2" android:layout_width="163dp" android:layout_height="49dp" android:src="@drawable/buttonevents"></ImageView>
        </LinearLayout>
    </FrameLayout> 
</LinearLayout> 

【问题讨论】:

  • 您在什么设备上进行测试,您的清单中的 minSdkVersion/targetSdkVersion 设置是什么?如果您省略这两个声明,Android 会假定您的应用在运行时以 API 1 为目标,并缩放您的 UI 以模拟 320x480 屏幕。

标签: android xml user-interface imageview scale


【解决方案1】:

您是否尝试过将 ImageView 的 scaleType 设置为 fitCenter?

【讨论】:

    【解决方案2】:

    android支持的计量单位可以是:

    像素
    像素 - 对应于屏幕上的实际像素。


    英寸 - 基于屏幕的物理尺寸。

    毫米
    毫米 - 基于屏幕的物理尺寸。

    pt
    点 - 基于屏幕物理尺寸的 1/72 英寸。

    dp
    Density-independent Pixels - 一个基于屏幕物理密度的抽象单位。这些单位与 160 dpi 屏幕相关,因此 1 dp 是 160 dpi 屏幕上的一个像素。 dp-to-pixel的比例会随着屏幕密度的变化而变化,但不一定直接变化;而是选择的比例是靠近屏幕的东西。

    sp
    Scale-independent Pixels - 这类似于 dp 单位,但它也根据用户的字体大小偏好进行缩放。建议您在指定字体大小时使用此单位,以便根据屏幕密度和用户偏好进行调整。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-03-06
      • 2019-08-01
      • 2011-05-05
      • 1970-01-01
      • 2014-09-09
      • 1970-01-01
      • 2019-03-30
      相关资源
      最近更新 更多