2011-07-08 57 views
1

我目前的佈局顯示不是全屏的活動(沒關係)。如何創建顯示在指定屏幕位置的android活動?

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="100dip" 
android:layout_height="200dip" > 

<TextView android:layout_height="wrap_content" android:id="@+id/textView1" 
    android:layout_width="fill_parent" android:text="@string/hello"></TextView> 

我還添加機器人:主題= 「@安卓風格/ Theme.Translucent」 體現了我的活動。

我的200x100dip活動現在顯示在左上角。我怎樣才能指定我的線性佈局(或我的活動)的位置?

回答

0

我相信你Activity的最外面的佈局元素(LinearLayout)將被放置在一個FrameLayout中,該FrameLayout是Android給出的父元素。我建議你讓layout_height和_width中的最外層佈局match_parent/fill_parent,然後在最外面的佈局上用gravity =「center」將其中的內容居中。通過讓最外面的佈局透明並且不捕捉點擊元素,它將顯示爲中間可見元素的佈局。如果我正確猜測這就是你想在這裏實現的。

2

您可以使用FrameLayoutRelativeLayout作爲最外層佈局。然後在dp或android:layout_centerInParent或類似的地方使用絕對位置。

+0

我將最外面的佈局更改爲相對佈局,我可以在dp中使用哪個參數? – DixieFlatline

0

把該佈局在您使用Android的另一個絕對佈局:layout_width =「FILL_PARENT」和android:layout_height =「FILL_PARENT」其他的你可以做的就是用這樣的:http://www.droiddraw.org/ 您可以手動移動你的元素與此同時,它會給你用來做到這一點的XML代碼。我發現它在android中佈局XML非常有用。

相關問題