Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android crop background

I have a LinearLayout with width set to fill_parent and height to wrap_content. Now I want to give it a background from a png file, but doing it in a traditional way causes the LinearLayout to resize in order to show the whole background instead of cropping the additional part.

How can I set the background of LinearLayout so it won't resize?

Thanks

like image 321
Sebastian Nowak Avatar asked Jul 21 '11 20:07

Sebastian Nowak


People also ask

How can I cut background in mobile?

Download the remove.bg Android app to your phone. Open it up. Now go ahead and select the image of which you want to remove the background from your library. Removing the background of your photo will only take a few seconds, you can also change the background to a different color or add another image from our presets.

How do you crop a background app?

Here's our top five best apps to remove background from photo for iPhone and Android in 2022: YouCam Perfect: Best Free Background Remover. PhotoCut Remove Background PNG. Magic Eraser Background Editor.


1 Answers

It appears that such thing is achievable only using the ImageView and setting the scaleType parameter accordingly. A quick workaround is to use FrameLayout and put the ImageView under another layout with transparent background.

Code:

<FrameLayout      xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent">      <ImageView         android:id="@+id/imageView1"         android:layout_width="match_parent"         android:layout_height="match_parent"         android:scaleType="centerCrop"         android:src="@drawable/background" />  </FrameLayout> 
like image 114
Sebastian Nowak Avatar answered Sep 30 '22 19:09

Sebastian Nowak