提问者:小点点

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" />

这是这一行的错误:android:layout_marginleft=“-6”

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

共2个答案

匿名用户

您需要将dp作为扩展:

android:layout_marginLeft="-6dp"

匿名用户

您得到了错误,因为您错过了维度单位DP。如果布局是相对布局或线性布局,Android接受负边距。请在此查看更多信息。