2011-06-14 97 views
0

我在我的xml中有图像视图,用于在背景图像的指定位置设置背景图像的图像,我将其设置为一个模拟器并且它可以工作,但是当我启动其他不同大小的图像视图模拟器改变它相对于背景图像的相应位置,所以如何在背景图像上设置图像视图,以便imageview不会改变其对于任何大小屏幕的位置 我正在提供我的代码...在此先感谢..在背景图像上设置图像的问题android

这里是我的splash.xml文件,按钮和imageview改变其位置wrt背景image..for不同势尺寸屏幕模拟器

<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> 

回答

0

没明白的问题,你可能会考虑一些上传的图像和给我们联系到他们。我唯一能说的是,在指示任何尺寸时,你必须避免使用px。这会让你的视图在每个设备上看起来不同,你可能不想要。

+0

那么我应该在PX的plase使用?如果我在的地方像素的则也问题不解决.. – 2011-06-14 06:47:59

+0

使用SP @ saurabh,你应该使用'dp'(密度独立像素)而不是'px':http://stackoverflow.com/questions/2025282/difference-of-px-dp-dip-and-sp-in-android – sfat 2011-06-14 06:50:06

+0

您可以使用dp,sp或dip。你可以看看这篇文章,以便说清楚: http://developer.android.com/guide/topics/resources/more-resources.html#Dimension – Egor 2011-06-14 06:50:39

0

使用dip而不是pxsp

你将XML

<?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> 

感谢 迪帕克

+0

在android中的错误:background =“@ drawable/a_thumb” – 2011-06-14 06:57:57

+0

这里a_thumb只不过是我绘制的文件夹中的图像名称。而不是a_thumb给你的图像名称 – 2011-06-14 09:51:01