【发布时间】:2014-06-22 11:21:53
【问题描述】:
我有这个布局:
<FrameLayout
android:id="@+id/artwork_detected_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginBottom="20dip"
android:layout_marginLeft="18dip"
android:layout_marginTop="20dip"
android:padding="6dip" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/txt_favourites"
android:textColor="@color/welcome_textcolor"
android:textSize="24sp" />
</FrameLayout>
<ImageView
android:id="@+id/btn_detect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/artwork_detected_text"
android:layout_alignParentRight="true"
android:layout_alignTop="@id/artwork_detected_text"
android:layout_centerVertical="true"
android:adjustViewBounds="true"
android:src="@drawable/detect_btn" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/artwork_detected_text"
android:layout_alignTop="@id/artwork_detected_text"
android:layout_centerVertical="true"
android:layout_toLeftOf="@id/btn_detect"
android:adjustViewBounds="true"
android:src="@drawable/back_btn" />
</RelativeLayout>
这是在eclipse图形布局中的样子
如果您注意到右侧两个 ImageView 的左侧和右侧有多余的填充。 我如何在没有
的情况下删除它为图像指定绝对宽度/高度(我希望它们从左侧的 TextView 中对齐顶部和对齐底部)
具有负边距/填充(必须根据屏幕密度进行调整)
我已经将adjustViewBounds属性设置为true,你可以在代码中看到,但显然它只修复了ImageViews顶部和底部不需要的填充,所以它在这里基本上没用。
附加信息: 图像很大 - 比显示的要大得多。但是正如您在此处看到的那样,它们的缩放比例正确。不,它们没有透明填充。
【问题讨论】:
-
好奇:你在实际设备上试过了吗?图形编辑器有时会有点问题。
-
是的,它看起来和eclipse预览中的一样。
-
您可以尝试删除 alignTop 和 alignBottom 属性吗?它们不应该与适当的 centerVertical 属性相关,并且可能会发生冲突。
-
它们是相关的,因为我希望高度相对于左侧 TextView 的大小。除非有其他方法可以做到这一点?
-
哦,对不起,我忘了你的图片更大了;只是试图缩小范围。也许尝试将 textview 权重设置为 1 的水平 LinearLayout?