2016-02-20 40 views
1

所以,我得到了一个卡通人物拿着白板的形象。给你一个想法,图像是这样的。如何在ImageView上的特定位置显示文本?

enter image description here

现在,我想表明通过TextView的这个白板的中央一些文字,字符持有的形象。要显示的文本不会太长,最长4-5个字符。是否有可能做这样的事情?如果是这样,那么执行此操作的方法是什么?

+2

使用画布...获取米奇板的坐标并在其上绘制文本。 –

+0

如何找到电路板的坐标? – Harry

+0

如果您使用的是ImageView,如果您想知道它是如何缩放的(因此白板的顶部/左侧角落在哪里),可以使用ImageView#getImageMatrix( )'方法 – pskink

回答

0

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

步骤1:所有的首先借此ImageView的一个相对布局

步骤2内:然后采取相对布局内的的FrameLayout。

3步:这里面的FrameLayout你可以把你的TextView,然后你可以通过为重力,填充等

下面是代码样本您的位置您的TextView!

<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

只有当纸板位于图像中心时,此答案才适用。如果董事会偏离中心怎么办? – Harry

+0

这个答案适用于整个图像。你只需要使用特定的宽度或高度来定位TextView –

+0

如何找到这个特定的宽度或高度? – Harry

0

试试这个布局。这可能会帮助你。

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

为了正确定位图像和文字,请相应地使用边距和填充。

相关问题