【问题标题】:Android XML ImageView marginLeft propertyAndroid XML ImageView marginLeft 属性
【发布时间】:2014-07-25 16:54:56
【问题描述】:

我需要将图像设置得比左边的元素更近。做到这一点的唯一方法是编辑图像,去掉所有的边距?如果我需要更近的地方怎么办?

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').

【问题讨论】:

    标签: android xml syntax-error


    【解决方案1】:

    你需要把dp作为扩展:

    android:layout_marginLeft="-6dp"
    

    【讨论】:

      【解决方案2】:

      您收到错误是因为您错过了尺寸单位 dp。如果布局是相对或线性布局,Android 接受负边距。查看更多here

      【讨论】:

        猜你喜欢
        • 2012-03-28
        • 1970-01-01
        • 2017-05-06
        • 1970-01-01
        • 1970-01-01
        • 2014-12-16
        • 2016-01-05
        • 2019-05-03
        • 2017-02-27
        相关资源
        最近更新 更多