problem in setting image over a background image android - android

i have image-view in my xml for setting the image over a background image at a specified place of back ground image i set it for one emulator and it works but when i launch other emulator of different size image-view change it corresponding position with respect to background image so how to set image view over a background image so that imageview not changes its position for any size of screen
i am providing my code ...thanks in advance..
here is my splash.xml file ,button and imageview changes its position w.r.t. background image..for diffrent size screen emulator
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/TheSplashLayout"
android:layout_gravity="center"
android:background="#drawable/splashmodified"
>
<ImageView
android:layout_width="60sp"
android:layout_height="60sp"
android:id="#+id/SplashImageView"
android:layout_gravity="center"
android:layout_marginTop="120sp"
android:layout_marginLeft="55sp"
/>
<Button
android:text="SUBMIT"
android:id="#+id/submitt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="75px"
android:layout_marginTop="300px"
/>
</RelativeLayout>

Did not understand the question, you might consider uploading some images and giving us links to them. Only thing I can tell is that you must avoid using px when indicating any dimensions. This will make your views look different on every device, that you probably don't want.

use dip instead of px and sp.
Your xml will be
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/TheSplashLayout"
android:layout_gravity="center"
android:background="#drawable/splashmodified"
>
<ImageView
android:layout_width="60dip"
android:layout_height="60dip"
android:id="#+id/SplashImageView"
android:layout_marginTop="120dip"
android:layout_marginLeft="55dip"
android:background="#drawable/a_thumb"
/>
<Button
android:text="SUBMIT"
android:id="#+id/submitt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="75dip"
android:layout_marginTop="300dip"
/>
</RelativeLayout>
Thanks
Deepak

Related

Scale background image and foreground image at same ratio in Android

I have a centered background image with a pattern that I am showing using an ImageView. I want it to fill the width and height of all the different screen sizes/densities, but maintain its aspect ratio. I think I have that part figured out, but then I have a foreground image (in a ToggleButton) that is smaller and centered and needs to scale at the same rate of the background image. This is important because the button image has graphical elements that need to align perfectly with the background. How do I get it to scale correctly? Here's what I've got so far:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relmain"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="centerCrop"
android:layout_centerInParent="true"
android:contentDescription="#string/bg_desc"
android:src="#drawable/bg_img" />
<ToggleButton
android:id="#+id/button"
android:background="#drawable/btn_on"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="center"
android:layout_centerInParent="true"
android:textOff=""
android:textOn=""
android:onClick="toggleLight" />
</RelativeLayout>
Thanks for taking a look!
I think you should do it like this according to my skills
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:layout_centerInParent="true"
android:contentDescription="#string/bg_desc"
android:background="#drawable/bg_img" />
May be it will look as you want.

ImageViews in a ListView not aligned vertically [Mono for Android]

I'm very new to developing apps to android, so bear with me.
Having said that, I'm trying to make a list with a image to the left and a title and description to the right of the image.
The image is downloaded from the web in the background and then set in the UI as they complete. This all works. However, the images are not aligned properly and I simply cannot understand why. I'm thinking it has something to do with the layout defined in the xml file? I tried using android:layout_alignParentLeft="true" and android:layout_gravity="left" but that got me nowhere.
Then I didn't know how to proceed, even after googling every way I could think of. I'm sorry if this is very basic, but I would really appreciate some help here.
Here's a pic of the situation:
And here's my layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/widget28"
android:layout_width="fill_parent"
android:layout_height="80px"
>
<ImageView
android:id="#+id/imageItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_alignParentLeft="true"
>
</ImageView>
<LinearLayout
android:id="#+id/linearText"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_marginLeft="10px"
android:layout_marginTop="10px"
>
<TextView
android:id="#+id/textTop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
>
</TextView>
<TextView
android:id="#+id/textBottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
>
</TextView>
</LinearLayout>
</LinearLayout>
I appreciate any help you can offer.
There're two ways to achieve what you desire:
1.Fix the ImageView width and height and use android:scaleType="fitXY". This sounds bad, but actually almost gallery apps I know use it in the thumbnail preview mode.
2.Set android:scaleType="fitStart". No promise this will work, depends on the ratio of width and height of the image source. But if all your image source are landscape style (width > height), this way should work.

Does the image in a LinearLayout must be the same size?

i have wrote a program to test the MediaPlayer class, and it has three ImageButtons——"play","pause" and "stop". at the beginning, i uses three different size .png pictures for the three ImageButtons, and the program cannot be run on my AVD, and then i changed them to three .png picutres that have the same size, then it runs correctly this time.
does the image uses in a LinearLayout must be the same size??
here is the latyout file:
<?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"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello"
/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageButton
android:id="#+id/play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/play">
</ImageButton>
<ImageButton
android:id="#+id/pause"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/pause">
</ImageButton>
<ImageButton
android:id="#+id/stop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/stop">
</ImageButton>
</LinearLayout>
</LinearLayout>
I have tested your code it is fine but problem was in images you remove .png in your image it will work. Cool because .png is already in image and you also add .png in images so that remove .png from image.
does the image uses in a LinearLayout must be the same size??
No. The wrap_content parameter will make the encapsulating LinearLayout only as big as the the largest ImageButton.
The problem may lie with the names of the drawables. Make sure your all your .png images follow android naming conventions (names can contain only lower case letters, the numbers 0-9, or an underscore).
Also check the images themselves aren't corrupt.

layout problem raise

This is my layout file is ::
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="#+id/relativeLayout1"
android:layout_width="wrap_content" android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#drawable/bg1"
>
<!-- <RelativeLayout android:id="#+id/relativeLayo"
android:layout_width="480dp" android:layout_height="320dp"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_marginLeft="20dp"
android:background="#drawable/bg1"> -->
<ImageView android:src="#drawable/lets_play"
android:layout_width="wrap_content" android:layout_marginLeft="260dp"
android:id="#+id/imageView1" android:layout_height="wrap_content"
android:layout_marginTop="40dp"
></ImageView>
<ImageView android:src="#drawable/show_me"
android:layout_width="wrap_content" android:layout_marginLeft="220dp"
android:id="#+id/imageView1" android:layout_height="wrap_content"
android:layout_marginTop="60dp"
></ImageView>
<ImageButton android:id="#+id/anim_btn_play"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="260dp" android:layout_marginTop="150dp"
android:src="#drawable/play">
</ImageButton>
</RelativeLayout>
And mobile output is like ::
![this][1]
now my problem is :: i would like to set 480 * 320 size screen and layout is starting from left. At right side there is black portion remain.i have approx ten activity and all activity are going to display same direction. now i would like to show in center like ::
![this][2]
so can you tell me solution?
Easiest method is to wrap your Relative layout with something else, probably linear layout would be fine, and then:
<linearlayout gravity=center>
<relativelayout width=480dp height=320dp>
...
It should quick fix your problem on particular 480x320 screen.
BUT, I would suggest you rethink about your background image to make it possible to adopt to screens with different aspect ratio, consider looking nine-patch and make the background 'strecthable' or make a custom drawable that will stay in middle of screen.

Images in my Layout scale up but the should not. How can I prevent the Images to be scaled?

I have a RelativeLayout in which I have two images. The problem is the scale up. They are displayed way bigger than the are supposed to. Here is my layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/gallery_batch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/batch_background">
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/icon_success"
android:id="#+id/view_batch_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:padding="5dp"
android:layout_gravity="center_vertical"/>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/text_bereits_geladen"
android:layout_toRightOf="#id/view_batch_icon"
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"/>
Can anybody tell me what I am doing wrong here?
The layout looks fine.
Where are you storing these images? For example, if you put them in the drawable-ldpi folder with the size you want, and then test on a emulator runing mdpi setting or hdpi settings the image will be bigger, you have to decide properly where to store them acording to your desing.
These tags dont need the xml name space, you can write them without that, that is only needed for the main tag of the xml file.
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"

Categories

Resources