有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Android包含自定义组件,导致其隐藏在主视图后面

我正在使用的应用程序有4个选项卡,其中3个共享许多功能,包括底部的导航栏和后退、编辑和地图按钮。在所有3个布局中都有完全相同的xml,所以我试图通过将xml提取到一个单独的组件(包括它)中,然后从那里开始,来解决这个问题

以前我有

<RelativeLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
                安卓:layout_height="fill_parent"
                安卓:layout_width="fill_parent">

        <RelativeLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
                        安卓:id="@+id/showedit_toolbar"
                        style="@style/showItemToolbar">

            <ImageButton 安卓:id="@+id/show_person_back_button"
                    style="@style/blackToolbarButton"
                    安卓:src="@drawable/left_white_arrow"
                    安卓:layout_alignParentLeft="true"/>

            <Button 安卓:id="@+id/show_person_map_button"
                    style="@style/blackToolbarButton"
                    安卓:text="map"
                    安卓:layout_alignParentRight="true"/>

            <Button 安卓:id="@+id/show_person_edit_button"
                    style="@style/blackToolbarButton"
                    安卓:text="edit"
                    安卓:layout_toLeftOf="@id/show_person_map_button"/>                          
        </RelativeLayout>

        <ScrollView xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
            安卓:layout_height="fill_parent" 
            安卓:layout_width="fill_parent"           
            安卓:layout_above="@id/showedit_toolbar"
            style="@style/CoinLightTheme">

// Lots more layout omitted

我将重复的部分提取到一个名为show_toolbar的xml文件中。xml,更改变量名称,使其在3个视图中更通用

<RelativeLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
    安卓:id="@+id/show_toolbar"
    style="@style/showItemToolbar">

    <ImageButton style="@style/blackToolbarButton"
        安卓:src="@drawable/left_white_arrow"
        安卓:layout_alignParentLeft="true" 
        安卓:id="@+id/show_back_button"/>

    <Button 安卓:id="@+id/show_map_button"
        style="@style/blackToolbarButton"
        安卓:text="map"
        安卓:layout_alignParentRight="true"/>

    <Button 安卓:id="@+id/show_edit_button"
        style="@style/blackToolbarButton"
        安卓:text="edit"
        安卓:layout_toLeftOf="@id/show_map_button"/>                         

</RelativeLayout>

然后在我原来的布局文件中,我用

<RelativeLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
                安卓:layout_height="fill_parent"
                安卓:layout_width="fill_parent">

    <include 安卓:id="@+id/show_toolbar" layout="@layout/show_toolbar"/>

    <ScrollView xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
        安卓:layout_height="fill_parent" 
        安卓:layout_width="fill_parent"
        安卓:layout_above="@id/showedit_toolbar"         
        style="@style/CoinLightTheme">

现在,问题是视图不再显示。我仍然可以点击按钮,它们会做出响应(即,如果我点击按钮应该在的角落,它仍然有效),但我看不到它们被绘制到的按钮或条

我找不到关于Include应该如何工作的很好的文档,所以可能我用错了。任何帮助都将不胜感激

之前

Before http://i34.tinypic.com/2dl0hm1.png

之后

After


共 (1) 个答案

  1. # 1 楼答案

    RelativeLayout支持小部件的垂直堆叠。根据您的布局,您的“工具栏”将隐藏在ScrollViewAFAICT后面。如果不希望出现这种行为,请调整布局,使它们不会重叠