我想用RelativeLayout在一个简单的对话框中显示一个由方向按钮包围的地图块。RelativeLayout不显示我所有的小部件
我已经尝试了一些变化,但不可避免地,我的一些按钮丢失了。
在此版本的示例中,缺少up
和left
按钮。如果我先声明up
按钮并将tile
按钮相对于它,则up
显示。 RelativeLayouts是否需要首先声明最上面的小部件?不要猜测,layout_above
然后...
我不能发布图片(低代表),但你可以查看结果here。
<?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="fill_parent"
>
<ImageView
android:id="@+id/tile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5px"
android:layout_centerInParent="true"
android:src="@drawable/loading"
/>
<Button
android:id="@+id/up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/tile"
android:layout_centerHorizontal="true"
android:drawableLeft="@drawable/up"
/>
<Button
android:id="@+id/left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/tile"
android:layout_centerVertical="true"
android:drawableLeft="@drawable/left"
/>
<Button
android:id="@+id/right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/tile"
android:layout_centerVertical="true"
android:drawableLeft="@drawable/right"
/>
<Button
android:id="@+id/down"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/tile"
android:layout_centerHorizontal="true"
android:drawableLeft="@drawable/down"
/>
<Button
android:id="@+id/in"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/tile"
android:layout_alignParentLeft="true"
android:text="@string/test_in"
/>
<Button
android:id="@+id/out"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/tile"
android:layout_alignParentRight="true"
android:text="@string/test_out"
/>
</RelativeLayout>
一个有用的建议,因为它使我重新考虑我应该如何分析RelativeLayouts ...但它也导致了使用的布局去全屏幕(在必要的'fill_parent'的组合的对话框布局以及方向按钮粘在两侧的事实)。 – 2010-10-25 13:47:07
这是由此产生的截图:http://emberapp.com/paour/images/kcoppock – 2010-10-25 13:47:34
啊,这确实有道理。虽然有截图很有用。您是否尝试将RelativeLayou更改为wrap_content?我认为这不会解决问题,但值得尝试。稍后我会看看我不能提出更好的解决方案。 – kcoppock 2010-10-25 14:09:20