2014-07-16 4 views
2

기기 화면 크기에 맞는 바탕 화면에 관한 다른 게시물을 각각 살펴 보았습니다. 각 방법을 시도했지만 아직 몇 가지 장치에서 설정이 실패합니다. 벽지가 기기의 정확한 화면 크기에 맞춰지면 아무도 도와 줄 수 있는지 궁금합니다. 여기 화면 크기로 화면 비율을 조정하지 않는 디스플레이 메트릭 표시

은 .... 그것이 바탕 화면으로 설정 한 후이 여기

after set as wallaper

이를 ...

Picture in app

벽지 응용 프로그램에서 사진입니다 그리고 내 Java 클래스입니다.

private static final String LOG_TAG = "Home"; 

private static final Integer[] THUMB_IDS = { 
     R.drawable.icarus_thumb, 
     R.drawable.koneko_thumb, 
     R.drawable.ic_launcher, 
}; 

private static final Integer[] IMAGE_IDS = { 
     R.drawable.icarus, 
     R.drawable.koneko, 
     R.drawable.ic_launcher, 
}; 

private Gallery mGallery; 
private boolean mIsWallpaperSet; 

@Override 
public void onCreate(Bundle icicle) { 
    super.onCreate(icicle); 
    requestWindowFeature(Window.FEATURE_NO_TITLE); 

    setContentView(R.layout.wallpaper); 

    mGallery = (Gallery) findViewById(R.id.gallery); 
    mGallery.setAdapter(new ImageAdapter(this)); 
    mGallery.setOnItemSelectedListener(this); 
    mGallery.setOnItemClickListener(this); 
} 

@Override 
protected void onResume() { 
    super.onResume(); 
    mIsWallpaperSet = false; 
} 

public void onItemSelected(AdapterView parent, View v, int position, long id) { 
    getWindow().setBackgroundDrawableResource(IMAGE_IDS[position]); 
} 

public void onItemClick(AdapterView parent, View v, int position, long id) { 

    Bitmap bitmap = BitmapFactory.decodeStream(getResources().openRawResource(IMAGE_IDS[position])); 

    DisplayMetrics metrics = new DisplayMetrics(); 
    getWindowManager().getDefaultDisplay().getMetrics(metrics); 
    int height = metrics.heightPixels; 
    int width = metrics.widthPixels; 


    WallpaperManager wallpaperManager = WallpaperManager.getInstance(this); 
    try { 

     wallpaperManager.setBitmap(bitmap); 

     wallpaperManager.suggestDesiredDimensions(width, height); 




    } catch (IOException e) { 
     e.printStackTrace(); 
    } 
} 

/* 
* When using touch if you tap an image it triggers both the onItemClick and 
* the onTouchEvent causing the wallpaper to be set twice. Synchronize this 
* method and ensure we only set the wallpaper once. 
*/ 
private synchronized void selectWallpaper(int position) { 
    if (mIsWallpaperSet) { 
     return; 
    } 
    mIsWallpaperSet = true; 
    try { 
     Bitmap bmap2 = BitmapFactory.decodeStream(getResources().openRawResource(IMAGE_IDS[position])); 
     DisplayMetrics metrics = new DisplayMetrics(); 
     getWindowManager().getDefaultDisplay().getMetrics(metrics); 
     int height = metrics.heightPixels; 
     int width = metrics.widthPixels; 
     Bitmap bitmap = Bitmap.createScaledBitmap(bmap2, width, height, true); 






     WallpaperManager wallpaperManager = WallpaperManager.getInstance(Wallpaper.this); 

     wallpaperManager.setBitmap(bitmap); 
     setResult(RESULT_OK); 
     finish(); 
    } catch (IOException e) { 
     Log.e(LOG_TAG, "Failed to set wallpaper " + e); 
    } 
} 

public void onNothingSelected(AdapterView parent) { 
} 

@Override 
public boolean onTouchEvent(MotionEvent event) { 
    selectWallpaper(mGallery.getSelectedItemPosition()); 
    return true; 
} 

public class ImageAdapter extends BaseAdapter { 

    private Context mContext; 

    public ImageAdapter(Context c) { 
     mContext = c; 
    } 

    public int getCount() { 
     return THUMB_IDS.length; 
    } 

    public Object getItem(int position) { 
     return position; 
    } 

    public long getItemId(int position) { 
     return position; 
    } 

    public View getView(final int position, View convertView, ViewGroup parent) { 
     ImageView i = new ImageView(mContext); 

     i.setImageResource(THUMB_IDS[position]); 
     i.setAdjustViewBounds(true); 
     i.setLayoutParams(new Gallery.LayoutParams(
       LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); 
     i.setBackgroundResource(android.R.drawable.picture_frame); 
     return i; 
    } 

} 

음, 고마워요. 누군가가 도울 수 있기를 바랍니다.

+0

설정 이미지보기 : 그것은 당신의 이미지 뷰의 화면 비율에 맞도록 scaleType은 = "fitXY는" –

+0

당신은 어디에을 적용하는 나에게 보여 주시겠습니까? – Shayden117

+0

XML 파일 –

답변

1

기본 이미지 자르기 도구를 사용하여 설정하십시오. 그것은 잘 작동합니다. 안드로이드로

Intent setAsWallpaperIntent = new Intent(Intent.ACTION_ATTACH_DATA); 
setAsWallpaperIntent.setDataAndType(uriToImage, "image/*"); 
startActivity(Intent.createChooser(setAsWallpaperIntent, "Set Image As")); 
관련 문제