【问题标题】:imageView Scale is correct on emulator but not on deviceimageView Scale 在模拟器上正确,但在设备上不正确
【发布时间】:2013-07-27 05:35:02
【问题描述】:

我的真实设备(手机)和模拟器上有不同比例的 ImageView。模拟器正确显示图像,但真实设备(电话)没有。设备(手机)屏幕上的图像变小。

这是我的java代码:

...

rootView = (ViewGroup) inflater.inflate(R.layout.arabic_page, container, false);
waraka = (ImageView) rootView.findViewById(R.id.waraka);
...
     InputStream istr;
            try {
//Search in OBB 
    istr = getExpansionFile().getInputStream(num_image+".png");
    Bitmap bitmap = BitmapFactory.decodeStream(istr);
    Drawable draw =new BitmapDrawable(getResources(),bitmap);
    waraka.setImageDrawable(draw);

这是我的布局代码:

<RelativeLayout 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:background="#FFFFFF"
        tools:context=".MainActivity">
        <ImageView
            android:id="@+id/waraka"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentTop="true" 
            android:scaleType="fitCenter"/></RelativeLayout>

【问题讨论】:

  • 你想要发生什么?图像是否具有相同的相对大小(相对于布局内)?

标签: android android-imageview


【解决方案1】:

您的 layout_width 和 layout_height 都有“wrap_content”。根据您手机的 dpi 分辨率,它的大小会有所不同。如果您希望特定尺寸在多个设备上看起来相对相同,则必须以 dps 为单位指定尺寸。 因此,将您的图像视图更改为:

<ImageView
        android:id="@+id/waraka"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentTop="true" 
        android:scaleType="fitCenter"/>

【讨论】:

    【解决方案2】:

    您应该通读此链接以了解不同的屏幕尺寸:Android Screens Support

    可能发生的情况是您的手机的屏幕密度比模拟器高得多,这就是为什么事情更小。尝试在布局中使用与密度无关的像素 (dp)。

    【讨论】:

      【解决方案3】:

      发生这种情况是因为模拟器和手机的屏幕分辨率不同,因此您无法确定图像在布局中会占用多少空间,除非您将其设置为维度点 (dp),因此:

      首先:为什么要同时使用这两种方法:

      android:layout_alignParentBottom="true"
      android:layout_alignParentTop="true" 
      

      第二:我认为这段代码对你有用:

      <ImageView
                  android:id="@+id/waraka"
                  android:layout_width="100dp"
                  android:layout_height="100dp"
                  android:layout_gravity="center"
                  android:scaleType="fitXY"/>
      

      【讨论】:

        猜你喜欢
        • 2018-12-12
        • 1970-01-01
        • 1970-01-01
        • 2012-09-21
        • 1970-01-01
        • 2011-04-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多