简体   繁体   English

Android可绘制对象的大小无法缩放

[英]Android drawables sizes not scaling

Alright, this seems like it can be a very confusing question but I'm going to try anyway. 好吧,这似乎是一个非常令人困惑的问题,但是我还是要尝试一下。

I am developing an application right now, and the only thing that you should know is that there are two drawables in this application. 我现在正在开发一个应用程序,您唯一应该知道的是此应用程序中有两个可绘制对象。

Both drawables have the same exact width. 两个可绘制对象具有相同的确切宽度。 There is a background drawable that obviously goes in the background of the XML. 有一个背景可绘制对象,显然是在XML的背景中。 And then theres an ImageView of a simple line. 然后有一个简单行的ImageView。 This line is a drawable aswell. 这条线也是可绘制的。

On some devices/emulators, the line is not the full width of its resolution. 在某些设备/仿真器上,该线不是其分辨率的整个宽度。 Despite the fact that both drawables have the same exact width. 尽管两个可绘制对象都具有相同的精确宽度。 And both are viewed in the same portrait mode. 两者都以相同的肖像模式观看。

Is there any fix to this? 有没有解决办法? Basically this line moves upwards and represents something important, but I can't have it be a different size than the background. 基本上,这条线向上移动并表示重要的内容,但是我不能让它的大小与背景不同。 I really don't fully understand why the background with a width of 600, and a line with a width of 600 isn't the same size on some devices. 我真的不完全理解为什么在某些设备上宽度为600的背景和宽度为600的行的大小不同。 Despite putting both drawables in the Drawable folder, and not one for the different resolutions. 尽管将两个可绘制对象都放在了Drawable文件夹中,但没有一个用于不同的分辨率。 I currently do not have any screenshots, I will make some if need be, but I hope someone knows why this problem is bugging me and if I am doing something wrong. 我目前没有任何屏幕截图,如有需要,我会做一些截图,但是我希望有人知道为什么这个问题困扰着我以及我做错了什么。 Can I perhaps tell the application that its resolution must be 800x600, so that all devices that are capable of showing that many pixels, will do so? 我能否告诉应用程序其分辨率必须为800x600,以便所有能够显示这么多像素的设备都可以这样做? If this is possible, how do I do this? 如果可能的话,我该怎么做? I hope someone is able to help a newbie out :) 我希望有人能够帮助新手:)

XML: XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/root"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background"
    android:gravity="top"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="-60dp"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_gravity="center_horizontal"
        android:src="@drawable/line" />  

</RelativeLayout>

尝试将imageview的scaleType设置为fitXY。

    android:scaleType="fitXY"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM