java - 低质量图像android开发

标签 java android bitmap png

我制作了一张 480x2500 的 Photoshop 图片,我想将其放入我的一项 Activity 中。 但是,安装 .apk 后,图像质量很差。我真的尝试了我在谷歌上找到的所有东西,但没有结果。我不是一个经验丰富的程序员,所以请花点时间解释所有可以帮助我的事情。 这是我的代码:

XML:

<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dip"
android:tileMode="repeat"
android:dither="true">

<ImageView
    android:id="@+id/imageView2"
    android:layout_width="fill_parent"
    android:layout_height="1166dp"
    android:adjustViewBounds="true"
    android:scaleType="fitXY"
    android:src="@drawable/secondbutton3" />

Java代码

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.PixelFormat;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.Menu;
import android.view.WindowManager;

public class Secondbutton extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        setContentView(R.layout.activity_secondbutton);
        getWindow().setFormat(PixelFormat.RGBA_8888);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DITHER);

        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inPreferredConfig = Bitmap.Config.ARGB_8888;
        Bitmap gradient = BitmapFactory.decodeResource(getResources(), R.drawable.secondbutton, options);

        findViewById(R.id.imageView2).setBackgroundDrawable(new BitmapDrawable(gradient));

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_secondbutton, menu);
        return true;
    }

    }

我试图删除图像的一小部分(以具有透明背景)但没有结果。 谢谢。

最佳答案

确保图像保存为 .png

此外,您可能希望通过 Android Asset Studio 运行它,它会针对不同的屏幕密度自动缩放图像。

Android Asset Studio

关于java - 低质量图像android开发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14057320/

相关文章:

android - 免费变换 Android 图像

java - 使用独特的页面映射创建页面

java - 在 Java 生产代码中使用 Junit Assert API 可以吗

Android : Difference between View. GONE 和 View.INVISIBLE?

java - 如何在不破坏 Android 的情况下将 Eclipse 工作区组织到文件夹中

android - 当 dex.force.jumbo=true 时,Dexopt 在非常大的 APK(无序 method_idx)上失败

Android Sherlock ActionBar 向上按钮

android - 无法使用 SetShadowLayer 在位图上放置阴影

java - Java多维数组问题

java - 生成 15 位随机数时最后 3 位始终为零