定位文本块和图像
我有三个文本块和一个图像,我希望在草图中显示的布局中适合。 (忽略一秒钟的红线)
(我知道质量很糟糕,如果有人可以推荐我一个体面的(开放)os x/linux图形编辑器,我会很感激它!(nope,not gimp !))定位文本块和图像
我的想法是,以解决这样的问题:
- 相对布局。
- 定位第二个文本块相对于第一个文本块。
例如为:
android:layout_below=text1
android:layout_ (make it "float" to screen's right edge - not sure how to do that, yet.
- 第三相对于所述第一和第二块中的文本块。
例如为:
android:layout_below=text2
android:layout_alignLeft = text1
确定。没有让我们看到图像。它的大小是任意的,所以我认为我可以适应它。如果你知道从草图中看到红线,但是应该相应地对齐图像。
android:layout_alignTop = text2
android:layout_alignBottom = text2
android:layout_alignLeft = text1
但是我不这样做的布局非常好,当我试图实现它这样的4条内容或多或少地在屏幕上四处撞倒,但我从来没有得到他们全部到位。
我能达到的最接近的是这个,但是我不喜欢在那里使用硬编码限制。恐怕它不是超级灵活的。
尽管我不得不限制图像的显示尺寸,但是我希望能够使用包围的文本块,机器人可以很聪明地根据自己的尺寸计算出尺寸。
<TextView
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:text="text1" />
<ImageView
android:id="image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="text1"
android:layout_marginRight="7dip"
android:layout_marginTop="5dip"
android:adjustViewBounds="true"
android:maxHeight="150sp"
android:maxWidth="150sp"
android:src="srcFile" />
<TextView
android:layout_marginTop="5dip"
android:id="text2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignTop="image"
android:layout_below="text1"
android:layout_toRightOf="image"
android:text="text2" />
<TextView
android:id="text3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="image"
android:layout_marginTop="10dip"
android:text="text3" />
所以我想听听你怎么想我的方法,如果有什么东西我可以改进,以及如何真正实现它。
编辑: 所以我想找到一个解决方案,因为我害怕它不够灵活,我可以放下这部分代码:
android:maxHeight="150sp"
android:maxWidth="150sp"
可以保持图像的比例并在无代码的情况下调整其大小。只需使用线性布局和重量的观点相应
<TextView
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="text1" />
<LinearLayout
android:id="@+id/ll"
android:layout_below="@+id/text1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="2"
android:orientation="horizontal" >
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="11"
android:adjustViewBounds="true"
android:src="srcFile" />
<TextView
android:id="@+id/text2"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="text2" />
</LinearLayout>
<TextView
android:id="@+id/text3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/ll"
android:text="text3" />
简单的解决方案可能是最好的。使用linear layout与方向设置为垂直或水平:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<TextView
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:text="text1" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<ImageView
android:id="image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginRight="7dip"
android:layout_marginTop="5dip"
android:adjustViewBounds="true"
android:maxHeight="150sp"
android:maxWidth="150sp"
android:src="srcFile" />
<TextView
android:layout_marginTop="5dip"
android:id="text2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="text2" />
</LinearLayout>
<TextView
android:id="text3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:text="text3" />
</LinearLayout>
但也有一个硬编码maxHeight/-width o.O – yoshi 2012-02-03 11:09:24
,那么你可以通过使用Display对象获取屏幕尺寸 – 2012-02-03 11:32:00
这将足以
修复形象标识作为
android:id="@+id/image"
,并在第二个文本使用
android:layout_toRightOf="@+id/image"
android:layout_below="@+id/text1"
对于第三只
android:layout_below="@+id/text2"
LinearLayouts ......,我也喜欢,他们很容易,但是进展缓慢 - 不要太多地使用它们。
。奇迹般有效!感谢那。 – yoshi 2012-02-03 13:29:37