How to implement an android:background that doesn't stretch?
You should use ImageView if you don't want it to stretch.
Background images will always stretch to fit the view.
You need to set it as a Drawable to force the image aspect to the object.
Otherwise, if you are sticking with the Button idea, then you will need to force the scaling in the button to prevent the image from stretching.
Code:
onCreate(Bundle bundle) {
// Set content layout, etc up here
// Now adjust button sizes
Button b = (Button) findViewById(R.id.somebutton);
int someDimension = 50; //50pixels
b.setWidth(someDimension);
b.setHeight(someDimension);
}
How to fill image in background without stretching?
Place your image file in Res/drawable instead of Res/mipmap.
Res/mipmap is for app launcher icons only
Try this:
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:id="@+id/view"
android:src="@drawable/landscape"
android:scaleType="center" />
Android. Layout background stretches
You can use an XML drawable that uses the tag to disable the stretching:
<bitmap android:src="@drawable/background" android:gravity="center" />
Don't stretch ViewPager background
Sorry, there are no 'centerCrop' option for background drawable. How I do it is set your use FrameLayout having the back contain the ImageView using centerCrop, then the front(top) will be your content with transparent background.
Related Topics
Android Imageview Adjusting Parent's Height and Fitting Width
Gradle and Multi-Project Structure
Detect If App Was Downloaded from Android Market
Android 4.3: How to Connect to Multiple Bluetooth Low Energy Devices
Android -- How to Position View Off-Screen
How to Resize the Avd Emulator (In Eclipse)
Menuitem Tinting on Appcompat Toolbar
How to Change Toolbar Home Icon Color
Highlighting Text Color Using HTML.Fromhtml() in Android
Using Build Types in Gradle to Run Same App That Uses Contentprovider on One Device
How to Draw Border on Just One Side of a Linear Layout
How to Show One Layout on Top of the Other Programmatically in My Case
Android-L Cardview Visual Touch Feedback
How to Make Drawerlayout to Display Below the Toolbar
Save Data and Change Orientation
How to Setlayoutparams() for an Imageview
How to Programmatically Get the List of Registered Users in Firebase