美好的一天! 如何实现第一个屏幕的外观?我想将图像视图拉伸到屏幕边缘,但我得到的是一个边缘有边距的图像视图。这是我的xml代码:
<ImageView android:layout_width="wrap_content"
android:layout_height="240dp"
app:srcCompat="@drawable/green_image"
tools:layout_editor_absoluteX="0dp"
android:id="@+id/imageView"
android:scaleType="centerCrop"
app:layout_constraintBottom_toBottomOf="parent" />
答案 0 :(得分:0)
通常要实现你想要拉伸ImageView的宽度,你的layout.xml应该是这样的:
您的imageView的父级布局不应在左侧或右侧上有任何边距和填充 其宽度应为 match_parent
并且您的图片视图在左侧或右侧上不应有页边距,其宽度应< strong> match_parent 。
例如,您将ImageView放在LinearLayout中:
<LinearLayout
android:layout_width="match_parent"
...
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp">
<ImageView
android:layout_width="match_parent"
...
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp" />
</LinearLayout>
marginLeft或marginRight = 0dp可以删除,只需添加它们就可以指出你不应该有边距
希望这会有所帮助。