Android 如何在图像视图下放置文本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10195557/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to put text under image view
提问by Vitaly Menchikovsky
I wrote some xml but still cant place the text on the center of the screen as image. I want to put the text after my image. On my xml just trying to put text on the center under the image. my xml is:
我写了一些 xml,但仍然无法将文本作为图像放在屏幕中央。我想把文字放在我的图片之后。在我的 xml 上只是试图将文本放在图像下方的中心。我的 xml 是:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffffff"
android:gravity="fill" >
<ViewFlipper
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/flipper"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:flipInterval="2000" >
<LinearLayout
android:id="@+id/Linear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:baselineAligned="false"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="@drawable/logonews" />
<TextView
android:id="@+id/textLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/imageLabel"
android:layout_gravity="center"
android:singleLine="true"
android:text="Israel News"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
</ViewFlipper>
</RelativeLayout>
回答by Dheeraj Vepakomma
If the CompoundDrawable
doesn't meet your needs, you may use a RelativeLayout
instead of a LinearLayout
like this:
如果CompoundDrawable
不能满足您的需求,您可以使用 aRelativeLayout
而不是LinearLayout
这样的:
<RelativeLayout
android:id="@+id/relative"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/imageLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@drawable/logonews" />
<TextView
android:id="@+id/textLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/imageLabel"
android:layout_centerInParent="true"
android:singleLine="true"
android:text="Israel News"
android:textSize="18sp"
android:textStyle="bold" />
</RelativeLayout>
回答by Warpzit
Considered using textview with drawable on top? http://developer.android.com/reference/android/widget/TextView.html#attr_android:drawableTop
考虑在顶部使用带有 drawable 的 textview 吗?http://developer.android.com/reference/android/widget/TextView.html#attr_android:drawableTop
in xml: android:drawableTop
在xml中: android:drawableTop