2016-02-20 106 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> 

爲了正確定位圖像和文字,請相應地使用邊距和填充。

相關問題