1

我制作了一张 480x2500 的 Photoshop 图像,我想将其放入我的一项活动中。但是,安装 .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;
    }

    }

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

4

3 回答 3

1

你如何从photoshop保存图像?透明PNG!带网页导出

于 2012-12-27T16:04:23.030 回答
1

确保图像保存为 .png

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

安卓资产工作室

于 2012-12-27T16:14:33.980 回答
0

This code worked for me

BitmapFactory.Options myOptions = new BitmapFactory.Options();
    myOptions.inDither = true;
    myOptions.inScaled = false;
    myOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;
    myOptions.inDither = false;
    myOptions.inPurgeable = true;
    Bitmap preparedBitmap = BitmapFactory.decodeResource(yourAppName.getSharedApplication().getResources(),
            R.drawable.yourImage, myOptions);
    Drawable background = new BitmapDrawable(preparedBitmap);
    ((LinearLayout) findViewById(R.id.yourLayoutId))
        .setBackgroundDrawable(background);
于 2012-12-27T17:54:50.297 回答