ImageView和TextView浮动(左/右)Android

问题描述:

我正在寻找一种方法来定位我的文字在我的imageview周围(所以像CSS浮动左/右)。ImageView和TextView浮动(左/右)Android

我该如何在Android中执行此操作?我已经使用android:layout_alignParentLeft="true"(定位左我的ImageView)和android:layout_alignParentRight="true"我的TextView但 的TextView来到旁边的ImageView的,不继续ImageView的下方时,我有很长的文字..

任何想法?

您需要使用RelativeLayout作为容器

+0

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

我也尝试了很多方法,但没有运气。我不认为文本会在当前的Android中流动,就像在html中一样。

+0

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

+1

不知道什么路径放入“src”值,虽然... – hwii77 2009-12-22 18:29:30

我有同样的问题试图让一个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> 

有没有简单的方法来完成这件事。您可以使用2个文本视图,一个位于imageview旁边,另一个位于imageview下方。如果你很幸运能够获得一个你需要包装文本的固定大小的图像(我是),计算适合图像旁边文本视图的字符数,并将你的字符串分为两部分。只要确保你不会在文字中间分割文字。

我也尝试过使用html,但为此我不得不使用webview,它很沉重,很脏。首选拆分文本版本。

你有两个选择:

  1. 随着LinearLayout中,设置方向为水平,因此 图像是先来休息。
  2. 随着RelativeLayout的,那里你可以指示 元素相对于一个到另一个的风格 机器人的属性位置:layout_toLeftOft,安卓layout_toRightOf, 安卓layout_below或Android:layout_alignParentTop,...

但是,对于某些操作而言,它不像CSS那么灵活,例如,在图像周围缠绕文本不容易实现。