2012-01-07 38 views
0

我如何在xml中定位一個按鈕。即時通訊與android SDK的使用Eclipse,我只是用邊緣把按鈕的位置。但我怎樣才能通過postion功能呢?示例XML位置函數?

+0

你能詳細說明你正在嘗試使用哪個api嗎? – nandeesh 2012-01-07 21:46:48

+0

試圖調試應用程序,並沒有得到任何篩選 – 2012-01-07 22:06:51

+0

所有即時通訊試圖將按鈕放在固定位置 – 2012-01-07 22:07:15

回答

1

使用xml在屏幕上放置按鈕將取決於您對根視圖組使用的內容。

沒有一個位置函數,比如你可能想要在哪裏設置按鈕的X和Y位置,並且有很好的理由。由於Android設備的硬件碎片化,如果您依靠硬編碼的X和Y座標(無論縱向還是橫向),編寫便攜式UI將會非常困難。

舉個例子,如果我想提出一個按鈕在屏幕的右下方,我有一個相對佈局:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
<Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/hello" 
    android:layout_alignParentBottom = "true" 
    android:layout_alignParentRight = "true"/> 
</RelativeLayout> 

這將會把一個按鈕在屏幕上的按鈕右側,無論畫面像素密度/分辨率甚至風景VS人像

+0

謝謝!除了如果我想集中它呢? – 2012-01-08 01:09:04

+0

layout_centerInParent http://developer.android.com/reference/android/widget/RelativeLayout.LayoutParams.html – snowCrabs 2012-01-08 20:47:47