如何将文本下图像视图 [英] how to put text under image view

查看:98
本文介绍了如何将文本下图像视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一些XML,但仍然无法到位的屏幕图像的中心的文本。 我希望我的形象后,把文本。 在我的XML只是试图把文本中央的图像下面。 我的XML是:

 < XML版本=1.0编码=UTF-8&GT?;
< RelativeLayout的的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =match_parent
    机器人:layout_height =WRAP_CONTENT
    机器人:后台=#FFFFFFFF
    机器人:重力=补>

    < ViewFlipper
        的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
        机器人:ID =@ + ID /脚蹼
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =FILL_PARENT
        机器人:layout_alignParentBottom =真
        机器人:flipInterval =2000>

        <的LinearLayout
            机器人:ID =@ + ID /线性
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_gravity =中心
            机器人:baselineAligned =假
            机器人:方向=垂直>

            < ImageView的
                机器人:ID =@ + ID / imageLabel
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_gravity =center_horizo​​ntal
                机器人:SRC =@可绘制/ logonews/>

            <的TextView
                机器人:ID =@ + ID /为textLabel
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_below =@ ID / imageLabel
                机器人:layout_gravity =中心
                机器人:单线=真
                机器人:文本=以色列新闻
                机器人:TEXTSIZE =18sp
                机器人:TEXTSTYLE =黑体/>
        < / LinearLayout中>
    < / ViewFlipper>

< / RelativeLayout的>
 

解决方案

如果在<一个href="http://developer.android.com/reference/android/widget/TextView.html#attr_android%3adrawableTop"><$c$c>CompoundDrawable不能满足你的需求,你可以使用的 RelativeLayout的代替的LinearLayout 是这样的:

 &LT; RelativeLayout的
        机器人:ID =@ + ID /相对
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT&GT;

        &LT; ImageView的
            机器人:ID =@ + ID / imageLabel
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_centerInParent =真
            机器人:SRC =@可绘制/ logonews/&GT;

        &LT;的TextView
            机器人:ID =@ + ID /为textLabel
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_below =@ ID / imageLabel
            机器人:layout_centerInParent =真
            机器人:单线=真
            机器人:文本=以色列新闻
            机器人:TEXTSIZE =18sp
            机器人:TEXTSTYLE =黑体/&GT;
    &LT; / RelativeLayout的&GT;
 

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 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>

解决方案

If the CompoundDrawable doesn't meet your needs, you may use a RelativeLayout instead of a LinearLayout like this:

    <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>

这篇关于如何将文本下图像视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆