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

标签 java android user-interface layout

我正在开发的应用程序有 4 个选项卡,其中 3 个选项卡共享许多功能,包括带有“后退”、“编辑”和“ map ”按钮的底部导航栏。在所有 3 个布局中都有完全相同相同的 xml,因此我尝试通过将该 xml 提取到一个单独的组件(包括它)中来干燥它,然后从那里开始。

以前我有

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

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

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

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

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

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

// Lots more layout omitted

我将重复的部分提取到名为 show_toolbar.xml 的 xml 文件中,更改了变量名称以使其在 3 个 View 中更加通用

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

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

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

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

</RelativeLayout>

然后在我的原始布局文件中,我将那大代码块替换为

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

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

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

现在,问题是 View 不再显示。我仍然可以单击按钮并且它们会做出响应(即,如果我单击按钮应该所在的角落,它仍然有效),但我看不到它们所绘制的按钮或栏。

我找不到关于 Include 应该如何工作的非常好的文档,所以也许我错误地使用了它。任何帮助将不胜感激

之前

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

之后

After

最佳答案

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

关于java - Android - 包含自定义组件会导致其隐藏在主视图后面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1646445/

相关文章:

java - 如何在没有xml的情况下在spring4中配置 "CommonsMultipartResolver"来上传文件

java - 将函数添加到 BigDecimal 变量

android 在单击图像按钮时使用动画交换两个 View

android - 我们可以获取在 android/kotlin 中动态创建的网格布局的单元格文本值吗?

ios - 在堆栈 View 内的 Uilabels 之间创建垂直线

Java矩阵包含ArrayList元素

java - 如何从 5 个数字生成长度为 4 的所有可能排列?

android - 如果我不想使用 butterknife,如何使用 ViewHolder

python - 将小部件添加到第三页会导致 Frames 调整大小

java - 如何从 (0,0) 坐标移动面板