2013-01-21 64 views
1

我正在用eclipse構建一個android應用程序,我正在努力掌握圖像在屏幕中的位置。我在相對佈局中放置了一個圖像,並且我希望圖像的邊框完全匹配屏幕的邊框,但是當我手動擴展圖像時,它永遠不適合,即使我將填充設置爲:/ (請參見右側一邊是好的,但不是左邊,這個問題甚至不是一個關於屏幕的尺寸)Android/Eclipse:處理圖像的大小

謝謝您的幫助

enter image description here

+0

檢查http://developer.android.com/reference/android/widget/ImageView.ScaleType.html – Nermeen

+0

謝謝,但如果我想要定位圖像中心,或左或右,這將是確定的。我不能給出確切的位置?我也想拉伸圖像 – morg

回答

0

如果你需要你的形象是問題您可以使用背景屬性的活動背景。

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/rootRL" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/background"> 
</RelativeLayout> 

「@ drawable/your_image_name」是您的圖片。圖片應該是google爲不同尺寸的屏幕推薦的尺寸。

+0

不,這不是活動的背景。 (請參閱圖片和紅色線條),我將使用它與一個觸摸監聽器 – morg

1

如果你想做到這一點,你需要使用此代碼屏幕尺寸:

// pixels 
Display display = getWindowManager().getDefaultDisplay(); 
Point size = new Point(); 
display.getSize(size); 
int width = size.x; 
int height = size.y; 

然後,你需要通過編程設置圖片的使用寬度和高度屬性的尺寸。