2012-04-20 51 views
7

我必須添加一個覆蓋(ImageView),以便它稍微移動到包含佈局左邊界的左側。外部/外部佈局之間的Android覆蓋

enter image description here

什麼是做到這一點的最好方法是什麼?

嘗試簡單的東西,比如把ImageView的佈局中,並使用負利潤率

android:layout_marginLeft="-20dip" 

這使得這樣的:

enter image description here

(更正:圖片中的文字應該是20dip不20px)

AbsoluteLayout已棄用。有沒有像z順序的東西?或者我該怎麼做?

在此先感謝。

編輯:我嘗試使用相對佈局。同樣的效果。下面是XML減少到最低限度:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:clipChildren="false" 
android:paddingLeft="50dip" 
> 

<ImageView 
    android:id="@+id/myId" 
    android:layout_width="60dip" 
    android:layout_height="60dip" 
    android:layout_marginLeft="-30dip" 
    android:clipChildren="false" 
    android:src="@drawable/pic" /> 

</RelativeLayout> 

結果 enter image description here

當含佈局具有比所述屏幕,而不是填充的背景圖像較小也恰好。

回答

13

使用RelativeLayout的代替的LinearLayout(允許重疊)和添加該給RelativeLayout的固定它:

android:clipToPadding="false" 
0

集 「機器人:clipChildren =假」 以xml

+1

不幫幫我。我把它放在包含的佈局和圖像視圖中,並沒有改變任何東西。 – Ixx 2012-04-22 07:03:14

0

使用一個透明的(機器人: backgroundview =「#00000000」)imageview在寬度= 30dp的線性佈局左側。在相對佈局的情況下,將myId設置爲向左對齊。如果使用線性佈局,則將方向設置爲水平,並讓透明圖像視圖成爲其中的第一個條目。

1

而不是

機器人:layout_marginLeft = 「 - 30dip」

嘗試

的android:paddingLeft = 「 - 30DP」