D
D
Dimas7042019-07-03 15:39:53
Java
Dimas704, 2019-07-03 15:39:53

How to set wallpaper to fit the screen?

Hello. I am new to android programming. In general, I'm making an application - a collection of wallpapers. The wallpaper is set, but not under the screen, but simply in the middle of the picture. I tried different methods to set the size for the image, but then when the wallpaper setting function is executed, the application crashes. How can I set the size of an image?
Java code:

import android.app.*;
import android.graphics.*;
import android.os.*;
import android.view.*;
import java.io.*;
import android.util.*;

public class wallpaper_one extends Activity 
{
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.wallpaper_one);
}
 int wallpaper = R.drawable.wallpaper;

public void setWallpaper(View v){
WallpaperManager wallpaperManager = WallpaperManager.getInstance(getApplicationContext()); 
try {
   wallpaperManager.setResource(wallpaper);
}
    catch (IOException e) {
            e.printStackTrace(); 
  }
 }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question