I make an application with wallpaper, when you install a picture on the main screen, it (the picture) is clipped in the center, how to make it so that it is not cut off?

My code

private ImageView mImageView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.full_image); // get intent data Intent i = getIntent(); // Selected image id int position = i.getExtras().getInt("id"); ImageAdapter imageAdapter = new ImageAdapter(this); mImageView = (ImageView) findViewById(R.id.full_image_view); mImageView.setImageBitmap(BitmapFactory.decodeResource(getResources(), imageAdapter.mThumbIds[position])); DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); int height = metrics.heightPixels; int width = metrics.widthPixels; Bitmap tempbitMap = (BitmapFactory.decodeResource(getResources(), imageAdapter.mThumbIds[position])); Bitmap bitmap = Bitmap.createScaledBitmap(tempbitMap, width, height, true); WallpaperManager wallpaperManager = WallpaperManager.getInstance(FullImageActivity.this); wallpaperManager.setWallpaperOffsetSteps(1, 1); wallpaperManager.suggestDesiredDimensions(width, height); try { wallpaperManager.setBitmap(bitmap); } catch (IOException e) { e.printStackTrace(); 

Errors

  java.lang.IllegalStateException: Could not find a method tempbitMap(View) in the activity class onlyspector.myapplication.FullImageActivity for onClick handler on view class android.widget.Button at android.view.View$1.onClick(View.java:3825) at android.view.View.performClick(View.java:4475) at android.view.View$PerformClick.run(View.java:18786) at android.os.Handler.handleCallback(Handler.java:730) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:176) at android.app.ActivityThread.main(ActivityThread.java:5419) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:525) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.NoSuchMethodException: tempbitMap [class android.view.View] at java.lang.Class.getConstructorOrMethod(Class.java:423) at java.lang.Class.getMethod(Class.java:787) at android.view.View$1.onClick(View.java:3818) at android.view.View.performClick(View.java:4475) at android.view.View$PerformClick.run(View.java:18786) at android.os.Handler.handleCallback(Handler.java:730) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:176) at android.app.ActivityThread.main(ActivityThread.java:5419) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:525) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862) at dalvik.system.NativeStart.main(Native Method) 

    1 answer 1

    Try to resize the image programmatically according to the screen size before setting it as wallpaper:

     DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); int height = metrics.heightPixels; int width = metrics.widthPixels; Bitmap tempbitMap = BitmapFactory.decodeResource(getResources(), R.drawable.img); Bitmap bitmap = Bitmap.createScaledBitmap(tempbitMap,width,height, true); WallpaperManager wallpaperManager = WallpaperManager.getInstance(MainActivity.this); wallpaperManager.setWallpaperOffsetSteps(1, 1); wallpaperManager.suggestDesiredDimensions(width, height); try { wallpaperManager.setBitmap(bitmap); } catch (IOException e) { e.printStackTrace(); } 

    Also in the manifest requires permissions:

     <uses-permission android:name="android.permission.SET_WALLPAPER_HINTS" /> <uses-permission android:name="android.permission.SET_WALLPAPER" /> 
    • It helped, but there were problems, the full picture disappeared, that is, a white background and just the "set wallpaper" button when you click on the button, the picture is set on the main screen as it should and after the application criticizes. corrected the code and added errors in the first post. I think the reason is in my clumsy hands - V01ume
    • I hope you don’t put a click listener through the markup? - Yuriy SPb
    • Everything works, there are no errors, but the problem with the picture is now, updated the first post, please see - V01ume
    • @ V01ume, do not change the question on the go. Your question was about the scale. If it is solved, mark the answer with the correct checkmark and ask another. - Yuriy SPb