2014-07-25 44 views
-1

我需要設置圖像靠近左側的元素。要做到這一點的唯一方法是通過編輯圖像來消除所有邊距?如果我需要它更接近?Android XML ImageView marginLeft屬性

marginLeft是否接受負值?

這是ImageView的是如何在XML文件:

<ImageView 
android:id="@+id/lineOneImageView" 
android:layout_height="wrap_content" 
android:layout_alignParentBottom="true" 
android:layout_centerVertical="false" 
android:layout_marginLeft="-6" 
android:layout_toRightOf="@id/productNameTextView" 
android:contentDescription="@string/text_placeholder" 
android:scaleType="fitXY" 
android:src="@drawable/img_i_black_normal" /> 

這是在這一行錯誤:機器人:layout_marginLeft = 「 - 6」

Error: Integer types not allowed (at 'layout_marginLeft' with value '-6'). 

回答

3

你需要把DP作爲擴展名:

android:layout_marginLeft="-6dp" 
2

您正在收到錯誤,因爲您錯過了尺寸單位dp。如果佈局是相對或線性佈局,則Android接受負邊距。查看更多here