首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在ImageView上显示特定位置的文本?

如何在ImageView上显示特定位置的文本?
EN

Stack Overflow用户
提问于 2016-02-20 07:56:53
回答 2查看 825关注 0票数 1

所以,我有一个卡通人物拿着白板的照片。给你一个想法,图像就像这样。

现在,我想通过文本视图在这个白板的中央显示一些文字,这是字符在图像中所持有的。要显示的文本不太长,最多为4-5个字符.有可能做这样的事吗?如果是的话,这样做的方法是什么?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-02-20 08:09:54

是的,这可以使用FrameLayout.来完成。

步骤1:首先将这个ImageView放在一个相对布局中

步骤2:然后在相对布局中取一个FrameLayout。

步骤3:在这个FrameLayout中,你可以拿出你的TextView,然后你可以通过重力,填充等来定位你的TextView。

这是您的代码示例!

代码语言:javascript
复制
<RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent" >


            /// this is your imageview
            <ImageView 
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>


            <FrameLayout 
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_centerInParent="true">

           <LinearLayout 
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <TextView 
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:gravity="center"
                        android:text="Enter Your Text Here"/>

           </LinearLayout>

          </FrameLayout>

</RelativeLayout>

如果这对你有用,请告诉我!)

票数 0
EN

Stack Overflow用户

发布于 2016-02-23 08:15:47

试试这个布局。这可能对你有帮助。

代码语言:javascript
复制
<FrameLayout
   android:layout_width="match_parent"
   android:layout_height="match_parent"
>

// this is your imageview
   <ImageView
        android:layout_gravity="center" /// you can change this property according to your requirement to 'right', 'left' etc
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

   <TextView
        android:layout_gravity="center"  /// you can change this property according to your requirement to 'right', 'left' etc
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="Enter Your Text Here"/>

</FrameLayout>

为了正确定位图像和文本,使用页边距和相应的填充。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35520623

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档