我想在屏幕上显示2个相对布局。一个低于另一个。我制作了这段代码,但它不起作用。在这种情况下,我只能看到两个上面的相对布局,虽然我设置了wrap_content,但这个布局占用了整个空间。
编辑!:我把第二个代码放在第二个代码之下。
编辑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>
答案 0 :(得分:1)
最好将LinearLayout与垂直方向一起作为两个子RelativeLayouts的Parent。如果您可以为RelativeLayouts设置80:20的高度权重,那么它将适合整个屏幕。
答案 1 :(得分:1)
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<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>
</ScrollView>
答案 2 :(得分:1)
<ScrollView 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:layout_width="match_parent"
android:layout_height="wrap_content" >
<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/hello_world" />
<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/hello_world" />
<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/hello_world" />
<!-- 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/hello_world" />
<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/hello_world" />
<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/hello_world" />
<!-- 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/hello_world" />
<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/hello_world" />
<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/hello_world" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/maps_manager_controls"
android:layout_width="match_parent"
android:layout_height="wrap_content"
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>
</ScrollView>
答案 3 :(得分:0)
请执行以下步骤: