2014-07-25 39 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