【发布时间】:2012-09-16 08:13:19
【问题描述】:
我有一个固定宽度和高度的单元格,设置为 100x100px。在该单元格内,我想显示一个带有边框的ImageView。
我的第一个想法是给ImageView放一个背景资源,并添加一个1dp的padding来创建边框效果:
<LinearLayout
android:layout_width="100dp"
android:layout_height="100dp" >
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/image_border"
android:padding="1dp"
android:src="@drawable/test_image" />
</LinearLayout>
显然这应该有效,但它没有,或者至少不像预期的那样。
问题是 ImageView 背景填充了整个 100x100px 单元格的空间,因此,如果图像的宽度小于 100px,则顶部和底部边框会显得更大。
注意黄色边框,我需要它在 ImageView 周围正好 1px:
非常感谢任何帮助、想法、建议。
【问题讨论】:
-
把内边距放在LinearLayout上,而不是imageview上。将lineaylayout的背景设置为黄色
-
这种情况下没有效果。
-
您是否尝试将
android:adjustViewBounds = "true"添加到您的ImageView。如果你想让它居中,你还需要添加android:layoutGravity = "center"。
标签: android android-layout android-emulator android-widget android-imageview