2010-11-21 141 views
1

我有一個絕對panel.I圖像設置我試圖設置它的位置通過code.But我沒有看到任何適用的方法/屬性來設置其位置。絕對佈局設置圖像位置

這是我的佈局。

<?xml version="1.0" encoding="utf-8"?> 
<AbsoluteLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    > 

<ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/marker" android:src="@drawable/marker" android:layout_y="106dp" android:layout_x="290dp"></ImageView> 
</AbsoluteLayout> 

這裏是我的代碼來設置其位置

marker = (ImageView)findViewById(R.id.marker); 
     marker.//Can't find a method or property 

回答

1
  • 不要使用AbsoluteLayout。它已被棄用。使用FrameLayout
  • 使用FrameLayout,您可以爲您的視圖創建一個FrameLayout.LayoutParams對象,並指定左側和頂部的邊距。
  • 如果你想動畫你的視圖,你可以使用TranslateAnimation

如果您需要添加多個元素,請將它們封裝到佈局中,並將它們放在FrameLayout下面。

+0

我在這個應用程序中有兩個圖像。如何讓圖像1移動到圖像2頂部的某個位置? – 2010-11-21 04:35:19

+0

在主佈局中也有一些按鈕。 – 2010-11-21 04:35:36

+0

Framelayout僅支持一個圖像? – 2010-11-21 04:37:11