新手问题:如何布局一个图标、两行文本和一个按钮?
我正在尝试扩展在 http://developer.html 中找到的示例。 android.com/resources/articles/layout-tricks-efficiency.html。我是一名全新的 MonoDroid 开发人员,昨天刚刚安装了它,并试图直接进入 UI 设计,但到目前为止它并不完全适合我。
我有这个 main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_marginRight="6dip"
android:src="@drawable/icon" />
<TextView
android:id="@+id/secondLine"
android:layout_width="200dip"
android:layout_height="26dip"
android:layout_toRightOf="@id/icon"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:singleLine="true"
android:ellipsize="marquee"
android:text="Second line which is a long line of text and needs to scroll" />
<TextView
android:id="@+id/firstLine"
android:layout_width="200dip"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/icon"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_above="@id/secondLine"
android:layout_alignWithParentIfMissing="true"
android:singleLine="true"
android:ellipsize="marquee"
android:gravity="center_vertical"
android:text="First line" />
<Button
android:id="@+id/logonButton"
android:layout_width="50dip"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/secondLine"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:gravity="center_vertical"
android:text="Login" />
/>
</RelativeLayout>
我想做的是在左侧有一个图标,在中间堆叠两行文本,在右侧有一个按钮。当我在模拟器中运行它时,我看到:
- 第二行不滚动。
- 该按钮不显示。
有没有一个简单的所见即所得的布局编辑器?或者是否有一个应用程序可以让我快速查看我的布局 XML?像 FireFox 中的 FireBug 这样的东西就可以了。
除非有 Droid 的 UI 助手的可能性很小,否则我做错了什么? :)
注意:我发现 hierarchyviewer 并且按钮根本没有显示(可见),尽管它确实显示在层次结构中。 http://screencast.com/t/rdjaR0tCM6
I am trying to extend a sample I found at http://developer.android.com/resources/articles/layout-tricks-efficiency.html. I am a brand new MonoDroid developer, just installed it yesterday, and trying to jump right into UI design and so far it is not clicking for me completely.
I have this main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_marginRight="6dip"
android:src="@drawable/icon" />
<TextView
android:id="@+id/secondLine"
android:layout_width="200dip"
android:layout_height="26dip"
android:layout_toRightOf="@id/icon"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:singleLine="true"
android:ellipsize="marquee"
android:text="Second line which is a long line of text and needs to scroll" />
<TextView
android:id="@+id/firstLine"
android:layout_width="200dip"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/icon"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_above="@id/secondLine"
android:layout_alignWithParentIfMissing="true"
android:singleLine="true"
android:ellipsize="marquee"
android:gravity="center_vertical"
android:text="First line" />
<Button
android:id="@+id/logonButton"
android:layout_width="50dip"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/secondLine"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:gravity="center_vertical"
android:text="Login" />
/>
</RelativeLayout>
What I am trying to do is have an icon on the left, 2 lines of text stacked in the middle and a button on the right. When I run this in my emulator I am seeing:
- The second line is not scrolling.
- The button does not show up.
Is there by any chance a simple WYSIWYG editor for layout? Or is there an app to give me a quick view of my layout XML? Something like FireBug in FireFox would be fine.
Barring the slim chance there are UI helpers for Droid, what am I doing wrong? :)
NOTE: I found hierarchyviewer and the button is not showing up at all (visible) though it does show in the heirarchy. http://screencast.com/t/rdjaR0tCM6
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你多了一个“/>”在 的底部。但这可能不是这里的主要问题。
如果旋转方向会发生什么?那么你收到按钮了吗?如果是这样,可能图像和文本的宽度太宽而无法容纳按钮。
I think you have an extra "/>" at the bottom of . But that may not be the main issue here.
What happens if you rotate the orientation? Do you get the button then? If so, maybe you have the width of the image and text too wide to accomodate the button.