【发布时间】:2012-02-03 10:54:14
【问题描述】:
我有三个文本块和一个图像,我想将它们放入草图中所示的布局中。 (忽略红线一秒钟。)
(我知道质量很糟糕。如果有人能推荐我一个体面的(开放的)用于 os x/linux 的图形编辑器,我将不胜感激!(不,不是 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"
【问题讨论】:
标签: android android-layout android-relativelayout android-imageview textview