1

活動の 1 つに入れたい 480x2500 のフォトショップ画像を作成しました。しかし、.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!Web へのエクスポートあり

于 2012-12-27T16:04:23.030 に答える
1

画像が .png として保存されていることを確認してください

また、さまざまな画面密度に合わせて画像を自動的にスケーリングする Android Asset Studio で実行することもできます。

Android アセット スタジオ

于 2012-12-27T16:14:33.980 に答える
0

このコードは私のために働いた

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 に答える