【发布时间】:2015-04-20 05:58:10
【问题描述】:
我已经看到了许多将 textview 与 imageview 对齐的方法,但我没有找到如何使文本大于图像,以及当您希望文本占据所有父布局时。我的布局是这样的:
<RelativeLayout
android:id="@+id/accordion_toogle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone">
<ImageView
android:id="@+id/accordion_image"
android:layout_width="@dimen/accor_img_wid"
android:layout_height="@dimen/accor_img_hei" />
<TextView
android:id="@+id/accordion_msg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/accordion_image"
android:paddingLeft="5dp"/>
</RelativeLayout>
在这种情况下,假设图像占据了RelativeLayout的一半,一旦imageView完成,accordion_msg继续占据relativeLayout的一半。
你懂我吗??我表达得好吗??有什么建议吗??
谢谢。
编辑 一张图片可以帮助我尝试做的事情:
粉红色的方块是图片,紫色和白色的矩形是文字必须在的地方,但到目前为止,紫色是空的。文字只占据白色方块。
编辑 2
我正在尝试@Elltz 所说的......但我无法做出我想要的,我有这个代码:
draw.setBounds(0, 0, width, height); //width: 128 height: 172 in this case
textview.setCompoundDrawablesRelative(draw, null, null, null);
但没有显示图像,我尝试了其他很多东西,例如:
textview.setCompoundDrawablesRelative(null, draw, null, null);
并且图像停留在文本的顶部。我尝试过的其他不同之处是:
textview.setCompoundDrawables(draw, null, null, null);
并且图像在左侧......但它在中心垂直对齐,并且图像的顶部和底部是空白的(没有文字,没有图片......没有任何东西)。我尝试将父级更改为 LinearLayout,使用重力左、重力顶部、RelativeLayout...
哎呀!现在布局是这样的:
<RelativeLayout
android:id="@+id/accordion_toogle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone">
<TextView
android:id="@+id/accordion_msg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/accordion_image"
android:paddingLeft="5dp"/>
</RelativeLayout>
*父级上的可见性并不重要,我以编程方式更改它。
谢谢。
【问题讨论】:
-
恐怕这会令人困惑。如果你能添加你正在得到的和你想要的图像,那会很有帮助。
-
我自己拥有这样的控制权,我更喜欢使用 LinearLayouts 并在父布局上设置 Gravity 属性,以便子布局符合。
标签: android android-layout textview imageview alignment