【发布时间】:2012-09-25 10:56:08
【问题描述】:
我想在我的屏幕上有 2 个相对布局。一个低于另一个。我制作了这段代码,但它不起作用。在这种情况下,我只能看到两者的上部相对布局,尽管我设置了 wrap_content,但此布局占用了整个空间。
编辑!:我把第二个代码下面也失败了。
EDIT 2!:我发现了问题……这有点……难过。问题在于我的主题。我将背景设置为太大的 png 文件,当我通过清单应用默认主题时,这发生了。当我删除它时,一切都很好。
这个版本也失败了。
新代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:id="@+id/some_id"
android:layout_above="@+id/some_id2"
android:layout_alignParentTop="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="@+id/main_button_localize"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/main_localize" />
</RelativeLayout>
<RelativeLayout
android:id="@id/some_id2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<ToggleButton
android:id="@+id/main_help"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
</RelativeLayout>
旧代码:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:id="@+id/maps_manager_menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" >
<!-- Top -->
<Button
android:id="@+id/maps_manager_top_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/empty" />
<Button
android:id="@+id/maps_manager_top_middle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/maps_manager_top_left"
android:contentDescription="@string/empty" />
<Button
android:id="@+id/maps_manager_top_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/maps_manager_top_middle"
android:contentDescription="@string/empty" />
<!-- Middle -->
<Button
android:id="@+id/maps_manager_middle_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/maps_manager_top_left"
android:contentDescription="@string/empty" />
<Button
android:id="@+id/maps_manager_middle_middle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/maps_manager_middle_left"
android:layout_below="@id/maps_manager_top_middle"
android:contentDescription="@string/empty" />
<Button
android:id="@+id/maps_manager_middle_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/maps_manager_middle_middle"
android:layout_below="@id/maps_manager_top_right"
android:contentDescription="@string/empty" />
<!-- Bottom -->
<Button
android:id="@+id/maps_manager_bottom_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/maps_manager_middle_left"
android:contentDescription="@string/empty" />
<Button
android:id="@+id/maps_manager_bottom_middle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/maps_manager_bottom_left"
android:layout_below="@id/maps_manager_middle_middle"
android:contentDescription="@string/empty" />
<Button
android:id="@+id/maps_manager_bottom_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/maps_manager_bottom_middle"
android:layout_below="@id/maps_manager_middle_right"
android:contentDescription="@string/empty" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/maps_manager_controls"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="true"
android:layout_below="@id/maps_manager_menu" >
<ToggleButton
android:id="@+id/maps_manager_help"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
</RelativeLayout>
【问题讨论】:
-
我在 eclipse 上检查过,我可以看到两个相对布局都在另一个之下。
-
将 match_parent 更改为 wrap_content
-
android:layout_alignBottom="true" by android:layout_alignParentBottom="true" 在第二个相对布局中
-
@RajeevNB 我的代码在您的 Eclipse 中有效吗?不变?我将 alignBottom 更改为 aliginParentBottom,什么也没发生。
-
@SardorDushamov 将匹配更改为换行,但在哪里?我想知道为什么 wrap_content 不起作用...