2009-12-21 114 views
15

我正在尋找一種方法來定位我的文字在我的imageview周圍(所以像CSS浮動左/右)。ImageView和TextView浮動(左/右)Android

我該如何在Android中執行此操作?我已經使用android:layout_alignParentLeft="true"(定位左我的ImageView)和android:layout_alignParentRight="true"我的TextView但 的TextView來到旁邊的ImageView的,不繼續ImageView的下方時,我有很長的文字..

任何想法?

回答

0

您需要使用RelativeLayout作爲容器

+0

是的,我使用RelativeLayout作爲周圍的佈局..但它不工作:s – wouter88 2009-12-21 15:45:10

1

我也嘗試了很多方法,但沒有運氣。我不認爲文本會在當前的Android中流動,就像在html中一樣。

+0

是否有可能,如果我使用HTML和標籤帶有float的標籤:留在它? – wouter88 2009-12-21 22:07:36

+1

不知道什麼路徑放入「src」值,雖然... – hwii77 2009-12-22 18:29:30

4

我有同樣的問題試圖讓一個ImageView對齊到一個RelativeLayout的左邊。我使用android:scaleType =「fitStart」來修復它。

我的XML文件:

<RelativeLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="horizontal" 
     android:layout_height="fill_parent" 
     android:layout_width="fill_parent" 
     android:padding="10dp"> 
    <ImageView 
     android:layout_height="50dp" 
     android:id="@+id/country_icon" 
     android:layout_alignParentLeft="true" 
     android:layout_width="wrap_content" 
     android:scaleType="fitStart" />   
</RelativeLayout> 
0

有沒有簡單的方法來完成這件事。您可以使用2個文本視圖,一個位於imageview旁邊,另一個位於imageview下方。如果你很幸運能夠獲得一個你需要包裝文本的固定大小的圖像(我是),計算適合圖像旁邊文本視圖的字符數,並將你的字符串分爲兩部分。只要確保你不會在文字中間分割文字。

我也嘗試過使用html,但爲此我不得不使用webview,它很沉重,很髒。首選拆分文本版本。

0

你有兩個選擇:

  1. 隨着LinearLayout中,設置方向爲水平,因此 圖像是先來休息。
  2. 隨着RelativeLayout的,那裏你可以指示 元素相對於一個到另一個的風格 機器人的屬性位置:layout_toLeftOft,安卓layout_toRightOf, 安卓layout_below或Android:layout_alignParentTop,...

但是,對於某些操作而言,它不像CSS那麼靈活,例如,在圖像周圍纏繞文本不容易實現。