Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/191.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 布局中的图像大小不正确_Android_Eclipse_Image_Layout - Fatal编程技术网

Android 布局中的图像大小不正确

Android 布局中的图像大小不正确,android,eclipse,image,layout,Android,Eclipse,Image,Layout,这就是它的样子: 我已将图像添加到布局中。因为图像是一个很大的小,最后在我的屏幕中间,没有填满整个屏幕的宽度,我不得不伸展它。这样一来,字母显然也延伸了,这让它看起来很糟糕。我知道这可能是不可改变的。每个图像都需要拉伸,因此颜色很好,但之后字母总是有点模糊。 如果这根本没有解决办法,就告诉我,让我知道。如果您认为您知道如何解决此问题,请帮助 我不认为这有什么关系,但这是我添加图像时使用的代码: <LinearLayout xmlns:android="http://schemas.and

这就是它的样子:

我已将图像添加到布局中。因为图像是一个很大的小,最后在我的屏幕中间,没有填满整个屏幕的宽度,我不得不伸展它。这样一来,字母显然也延伸了,这让它看起来很糟糕。我知道这可能是不可改变的。每个图像都需要拉伸,因此颜色很好,但之后字母总是有点模糊。 如果这根本没有解决办法,就告诉我,让我知道。如果您认为您知道如何解决此问题,请帮助

我不认为这有什么关系,但这是我添加图像时使用的代码:

<LinearLayout 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:orientation="vertical"
    tools:context="com.example.rodekruis.MainActivity">


    <ImageView
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:src="@drawable/rkz_logo4"
          android:layout_marginBottom="30dp"
           android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:scaleType="fitXY"
         />

尝试删除android:scaleType=“fitXY”属性,并在android:layout\u width=“wrap\u content”上替换android:layout\u width=“fill\u parent”


创建MyImageView.class

public class MyImageView extends ImageView {

public final static int WIDTH_IMAGE = 640;
public final static int HEIGHT_IMAGE = 200;
public MyImageView(Context context) {
    super(context);
}

public MyImageView(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public MyImageView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
}

@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int width = MeasureSpec.getSize(widthMeasureSpec);
    int height = width * HEIGHT_IMAGE / WIDTH_IMAGE;
    setMeasuredDimension(width, height);
}
}
在xml中

<?xml version="1.0" encoding="utf-8"?>
<your.package.MyImageView    xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/image_banner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/rkz_logo4"
android:layout_marginBottom="30dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"/>


最简单也是可能唯一的解决方案是在photoshop中编辑它,或者使用类似于photoshop online的东西:这是一个你总是要解决的问题。您必须提供适合所有屏幕的图像。看这里:。这意味着,您必须根据屏幕大小/密度在布局文件夹中放置不同的图像…android:scaleType=“center”或android:scaleType=“centerInside”或android:scaleType=“centerCrop”问题在于图像分辨率,因为屏幕截图中的图像并不复杂且难以创建,最后一个也是最好的解决方案是在绘图软件中创建分辨率更高的图像,我正在尝试用画法创建一幅图片,但我必须创建它,并将其瘦身,因为我知道在布局中它会伸展。当我痛苦地瘦身它时,分辨率已经在下降,所以当它伸展时,尺寸是好的,但分辨率不好,因为我无法保持它与我发现的图像相同的形状。我在另一篇帖子上得到了相反的评论,中心裁剪使它完全放大,FitXY只是将它伸展。两者都不是理想的结果,但FitXY离我们更近了,因为颜色被向右拉伸,从而将图像缩小。一切都很清楚,但它的宽度不足以从左到右填充我的屏幕,这正是我想要的。您可以将可绘制转换为位图,调整位图大小,并通过编程进行设置
<?xml version="1.0" encoding="utf-8"?>
<your.package.MyImageView    xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/image_banner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/rkz_logo4"
android:layout_marginBottom="30dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"/>