I want to use an image which is smaller than width of the screen, but has height bigger than the screen. I was thinking to use scroll view, that the whole image could be used, but fitting changes original ratio of the picture. How can I make it to adjust width and increase height by the same ratio? Here is the code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/tutorial"
>
<ScrollView
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="#drawable/tutorial">
</ImageView>
</ScrollView>
</LinearLayout>
you don't use fill_parent you want use match_parent
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:backround="#drawable/tutorial"/>
use android:scaleType="CENTER_INSIDE" in Your Imageview thats it.
for more details
read more about CENTER_INSIDE here
Related
Background image doesn't fill Linearlayout and changes that size
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#mipmap/dashboard_background"
android:orientation="vertical"
android:padding="10dp">
desirable look is this
How can I reach that?
You should use a frame layout with an imageview and a linearlayout inside
<FrameLayout
android:id="#+id/FrameLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:src="#drawable/background"/>
<LinearLayout
---Your Layout---
</LinearLayout>
Background always stretches to its View size. So you can't really control how it will look like. Instead, put an ImageView as a bottom most (meaning that it will lay under everything else) element in your layout, and use your background image as a source (src) for this ImageView, and so you will be able to control the look of the background with scaleType (probable you would want to use centerCrop or fitCenter). More about scaleType here.
In the end your layout should look something like this:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitCenter"
android:src="#mipmap/dashboard_background" />
<FrameLayout
android:id="#+id/content_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Put your view elements here -->
</FrameLayout>
</FrameLayout>
I am trying to achieve the following progress dialog (without the text)
My current XML code is as follows:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/background"
android:orientation="vertical"
>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/background"
>
<ProgressBar
android:id="#+id/progress_bar"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerVertical="true"
android:visibility="gone"
/>
I am programatically hiding and showing the progress bar when required (and hiding/showing other screen elements), all of which are under the Relative Layout in the XML code above.
However, whenever the Progress Bar shows, it appears centered at the top of the screen instead of being centered horizontally AND vertically.
Setting the ScrollView's attribute "fillViewport" to true should do it.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/background"
android:orientation="vertical"
android:fillViewport="true"
>
also make sure its child's height is set to "fill_parent" and the ProgressBar is properly centered
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
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 the first image is my activity while the second image is my phone on screen lock. How to I achieve this?
try to setscale to center crop. Maybe this will work you
<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>
You cannot apply scaleType to a background image. Instead, you can change the layout to include an ImageView as the background, and other elements as the foreground.
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/the_man_in_the_coat_image"
android:scaleType="fitCenter" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- ADD YOUR OTHER ELEMENTS -->
</LinearLayout>
</FrameLayout>
Maybe you should try to setscale to center crop. Maybe this will work you
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</LinearLayout>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="#drawable/image"
android:scaleType="fitCenter" />
</FrameLayout>
I hope this one help
I'm creating an activity on Android. I want to show a background image in it. I put a ImageView into my main RelativeLayout.
<RelativeLayout
android:id="#+id/relativeLayoutMain"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:orientation="vertical" >
<ImageView
android:id="#+id/bgImage"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:src="#drawable/bg4"
android:scaleType="centerCrop" />
</RelativeLayout>
It makes view like this.
I need to make view like this
How can I do it?
Try set ImageView attribute ScaleType=fitEnd ?
use this code.it's give the out-put as you want.
Code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:id="#+id/relativeLayoutMain"
android:layout_width="150dp"
android:background="#android:color/background_dark"
android:layout_height="150dp" >
<ImageView
android:id="#+id/bgImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:scaleType="centerCrop"
android:src="#drawable/ic_launcher" />
</RelativeLayout>
</RelativeLayout>
one advice if u give the imageview width fill parent then it's contain whole space according to main container.
Best Luck
Set the android:background="#drawable/bg4" in the RelativeLayout like that:
The whole XML should look like that:
<RelativeLayout
android:id="#+id/relativeLayoutMain"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:background="#drawable/bg4
android:orientation="vertical" >
</RelativeLayout>
First, I believe there are a couple of things wrong in the xml:
RelativeLayout does not make use of an orientation, you should remove that
Is this your full xml file? If so then the alignParentLeft in the RelativeLayout doesn't do anything because that is an attribute you use if it's parent is a RelativeLayout.
fill_parent is the deprecated name of match_parent, you should use that.
I also believe that code you have would center the image on the screen putting anything that is to big evenly on both sides and not at all what you said it does.
If you just want a background you can just use android:background="#drawable/bg4" in the RelativeLayout
EDIT: Changing the layoutparams of the ImageView to wrap_content both height and width and removing the scaleType alltogether might make it like you wanted it to be.
I would like an imagview that takes up the width of the screen (or layout) but there seems to be padding around the view that prevents me from doing this.
With the corresponding xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent" android:weightSum="1">
<ImageView android:src="#drawable/icon" android:background="#null"
android:layout_height="106dp" android:id="#+id/imageView1"
android:layout_weight="0.59" android:layout_width="match_parent"></ImageView>
</LinearLayout>
The padding is come from transparent area on android icon.
Just remove unused transparent area or use another image.
Try changing:
android:layout_width="match_parent"
to:
android:layout_width="fill_parent"
make layout width and height as fill_parent
<ImageView android:src="#drawable/icon" android:background="#null"
android:layout_height="fill_parent" android:id="#+id/imageView1"
android:layout_weight="1" android:layout_width="fill_parent"></ImageView>