Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android: (bad)low image quality in layout background

I tried all the answers that i found in the Android section with out any success before i post this question...
for some reason the image quality in the device is poor and in Eclipse and in the virtual device is very good
look on the screenshot example: example http://img714.imageshack.us/img714/1358/84044294.jpg

what should i do? i try to make the image with 72dpi and 300 dpi, the PNG/JPG resolution is 1280x800 but nothing works...
Please help!!

This is my LiveNewsActivity.java maybe i'm doing something wrong?

package com.prog.livenews;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.PixelFormat;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;


public class LiveNewsActivity extends Activity {
/** Called when the activity is first created. */

//############################
//######### VARS #############

Button login;
Button register;

//############################
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.test);
    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.bg, options);

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

    login = (Button) findViewById(R.id.main_login_button);
    register = (Button) findViewById(R.id.main_register_button);



    login.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            startActivity(new Intent("com.prog.livenews.LOGIN"));
        }
    });

    register.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            startActivity(new Intent("com.prog.livenews.REGISTER"));
        }
    });


}

}
like image 777
Ofir Hadad Avatar asked Dec 22 '22 00:12

Ofir Hadad


1 Answers

try it:

put it before setContentView(layoutId) on your first activity

getWindow().setFormat(PixelFormat.RGBA_8888);

and after call setContentView(layoutId) in your first activity you put the bellow code:

BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
options.inDither = true;
options.inScaled = false;
options.inDither = false;
options.inPurgeable = true;
Bitmap preparedBitmap = BitmapFactory.decodeResource(yourAppName.getSharedApplication().getResources(),
            R.drawable.bg, options);
    Drawable background = new BitmapDrawable(preparedBitmap);
    ((LinearLayout) findViewById(R.id.yourLayoutId))
        .setBackgroundDrawable(background);

and finnaly you put your xml images in res/drawable "if you have xml images" folder and the png, jpeg and others normals images you put in res/drawable-hdpi folder.

Hope this helps.

like image 140
ademar111190 Avatar answered Jan 08 '23 00:01

ademar111190