2011-06-14 120 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