Jackson Siro Jackson Siro - 19 days ago 5
Android Question

How to set an activity's layout background width to 100%

I am using this code to get the device background to be the background for my activity's layout.

final WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
final Drawable wallpaperDrawable = wallpaperManager.getDrawable();

MyHome = (GridView) findViewById(R.id.gridView1);
MyHome.setBackgroundDrawable(wallpaperDrawable);


However I want to have the width of the background to be as that which is in the device's theme as show in this image here enter image description here the first image is my activity while the second image is my phone on screen lock. How to I achieve this?

Answer

try to setscale to center crop. May this will work. For example

<FrameLayout  
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent">

  <ImageView
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"
        android:src="@drawable/my_image"
        android:scaleType="fitCenter" />

  <LinearLayout
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent">
  </LinearLayout>

</FrameLayout>
Comments