Android:使用alignBaseline作为文本后面的图像 [英] Android: Using alignBaseline for an image following text
问题描述
下面是一个TextView,后跟RelativeLayout中包含的ImageView。我试图让图像的底部与文本的基线对齐。当我使用alignBaseline作为图像时,引用TextView,它是图像的顶部,与文本的基线而不是底部对齐。我该如何解决这个问题?
Below is a TextView followed by an ImageView contained in RelativeLayout. I'm trying to get the bottom of the image to align with the baseline of the text. When I use alignBaseline for the image,reference the TextView, it is the top of the image that aligns with the baseline of the text instead of the bottom. How can I fix this?
<TextView
android:id="@+id/month"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="feb"
android:textSize="60px"
android:typeface="serif"
/>
<ImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:paddingLeft="15px"
android:layout_toRightOf="@id/month"
android:layout_alignBaseline="@id/month"
android:src="@drawable/minicalimage"
android:id="@+id/calimage"
/>
推荐答案
我能够完成我想做的事情。我没有使用alignBaseline,只是修复了填充和调整图像大小的问题。我所遇到的一些问题是由于图像太大而且不希望地填满了空间。我用来实现我想要的代码如下:
I was able to accomplish what I wanted to do. I did not utilize alignBaseline, just fixed the problem with padding and resizing the image. Some of the issues I was having arose from having an image too big and it filling up the space undesirably. The code I used to achieve what I wanted is below:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="25px"
android:paddingTop="30px"
android:id="@+id/LinearLayout1">
<TextView
android:id="@+id/month"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="feb"
android:textSize="60px"
android:typeface="serif"
/>
<ImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_toRightOf="@id/month"
android:layout_alignBottom="@id/month"
android:paddingBottom="12px"
android:src="@drawable/minicalimage"
android:id="@+id/calimage"
/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="2011"
android:id="@+id/year"
android:layout_toRightOf="@id/calimage"
android:layout_alignBaseline="@id/month"
android:typeface="serif"
android:textSize="40px"
/>
</RelativeLayout>
结果如下:
This was the result:
这篇关于Android:使用alignBaseline作为文本后面的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!