java - ParentBottom View 的 View.Gone 导致问题

标签 java android xml android-layout

我有一个照片应用程序,我在屏幕底部显示 admob 横幅。我从 java 管理它,并在需要时隐藏它。当我显示如下广告时,它工作正常

image

但是当我隐藏横幅时......底部导航工具栏位于顶部,屏幕显示空白,如下所示

image

我的 XML 如下所示。请检查并帮助我解决我的问题。 值为 ll_adLayout_latest 的 xml 底部是 adview。 谢谢

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:background="@color/image_back"
        android:layout_height="match_parent"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:fab="http://schemas.android.com/apk/res-auto"
        tools:context="com.karopass.karoshare.ImageDetails">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar_imageDetails"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorPrimary"
            android:theme="@style/AppTheme.AppBarOverlay"
            app:popupTheme="@style/AppTheme.PopupOverlay">
        </android.support.v7.widget.Toolbar>

        <com.example.utils.ExtendedViewPager
            android:id="@+id/view_pager_extended"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_above="@+id/pageNavCount"
            android:layout_below="@+id/toolbar_imageDetails"
            android:background="@color/image_back"/>

        <LinearLayout
            android:id="@+id/pageNavCount"
            android:orientation="horizontal"
            android:layout_above="@+id/pageNavLayout"
            android:layout_width="match_parent"
            android:layout_height="20dp">



            <RelativeLayout
                android:layout_weight="3"
                android:id="@+id/new_time_count"
                style="@style/SelectableItemBackground"
                android:layout_width="0dp"
                android:layout_height="match_parent">

                <TextView
                    android:id="@+id/txt_view"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="1 Month ago"
                    android:textSize="12sp"
                    android:paddingLeft="5sp"
                    android:layout_centerVertical="true"
                    android:textColor="#cccccc"
                    android:gravity="center|start" />
            </RelativeLayout>







            <RelativeLayout

                android:layout_weight="1"
                android:id="@+id/new_share_count"
                style="@style/SelectableItemBackground"
                android:layout_width="0dp"
                android:layout_height="match_parent">
                <TextView
                    android:id="@+id/share_count"
                    android:layout_centerInParent="true"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="999"
                    android:textSize="12sp"
                    android:paddingLeft="5sp"
                    android:layout_centerVertical="true"
                    android:textColor="#cccccc"
                    android:gravity="center|start" />
            </RelativeLayout>

            <RelativeLayout

                android:layout_weight="1"
                style="@style/SelectableItemBackground"
                android:id="@+id/new_save_count"
                android:layout_width="0dp"
                android:layout_height="match_parent">

                <TextView
                    android:id="@+id/like_count"
                    android:layout_centerInParent="true"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="999"
                    android:textSize="12sp"
                    android:paddingLeft="5sp"
                    android:layout_centerVertical="true"
                    android:textColor="#cccccc"
                    android:gravity="center|start" />
            </RelativeLayout>



        </LinearLayout>



        <LinearLayout
            android:background="@color/colorPrimary"
            android:id="@+id/pageNavLayout"
            android:orientation="horizontal"
            android:layout_above="@+id/ll_adLayout_latest"
            android:layout_width="match_parent"
            android:layout_height="48dp">



            <RelativeLayout
                android:layout_weight="1"
                android:id="@+id/new_time"
                style="@style/SelectableItemBackground"
                android:clickable="true"
                android:layout_width="0dp"
                android:layout_height="match_parent">

                <ImageView
                    android:layout_centerInParent="true"
                    android:scaleType="fitCenter"
                    android:src="@mipmap/ic_past_961"
                    android:layout_width="@dimen/nav_but_size"
                    android:layout_height="@dimen/nav_but_size" />
            </RelativeLayout>-->


            <RelativeLayout
                android:id="@+id/new_copy"
                android:clickable="true"
                style="@style/SelectableItemBackground"
                android:layout_weight="1"
                android:layout_width="0dp"
                android:layout_height="match_parent">

                <ImageView
                    android:layout_centerInParent="true"
                    android:src="@mipmap/ic_copy_96"
                    android:layout_width="@dimen/nav_but_size"
                    android:layout_height="@dimen/nav_but_size" />

            </RelativeLayout>


            <RelativeLayout

                android:layout_weight="1"
                android:id="@+id/new_save"
                style="@style/SelectableItemBackground"
                android:clickable="true"
                android:layout_width="0dp"
                android:layout_height="match_parent">
                <ImageView
                    android:layout_centerInParent="true"
                    android:src="@mipmap/ic_save_96"
                    android:layout_width="@dimen/nav_but_size"
                    android:layout_height="@dimen/nav_but_size" />
            </RelativeLayout>


            <RelativeLayout

                android:layout_weight="1"
                android:id="@+id/new_share"
                style="@style/SelectableItemBackground"
                android:clickable="true"
                android:layout_width="0dp"
                android:layout_height="match_parent">
                <ImageView
                    android:layout_centerInParent="true"
                    android:src="@mipmap/ic_share_96"
                    android:layout_width="@dimen/nav_but_size"
                    android:layout_height="@dimen/nav_but_size" />
            </RelativeLayout>


            <RelativeLayout

                android:layout_weight="1"
                style="@style/SelectableItemBackground"
                android:clickable="true"
                android:id="@+id/new_fav"
                android:layout_width="0dp"
                android:layout_height="match_parent">

                <ImageView
                    android:layout_centerInParent="true"
                    android:src="@mipmap/ic_hearts_96"
                    android:layout_width="@dimen/nav_but_size"
                    android:layout_height="@dimen/nav_but_size"/>
            </RelativeLayout>



        </LinearLayout>

        <LinearLayout
            android:id="@+id/ll_adLayout_latest"
            android:layout_alignParentBottom="true"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:gravity="bottom"
            android:orientation="vertical">

        </LinearLayout>

    </RelativeLayout>

最佳答案

那是因为你有

<LinearLayout
            android:background="@color/colorPrimary"
            android:id="@+id/pageNavLayout"
            android:orientation="horizontal"
            android:layout_above="@+id/ll_adLayout_latest"
            android:layout_width="match_parent"
            android:layout_height="48dp">

设置为位于ll_adLayout_latest上方,当您将其设置为View.GONE时,布局将被重新检查,就好像ll_adLayout_latest根本不在布局中一样。

您可以执行这两件事之一(或两者都执行,具体取决于您最终需要的行为。)。

  1. 将布局设置为不依赖于 ll_adLayout_latest 的位置。
  2. 使用 View.INVISIBLE 而不是 View.GONE

使用View.INVISIBLE时,布局不会表现得好像ll_adLayout_latest从未存在过一样,它将保留您已建立的依赖关系。

关于java - ParentBottom View 的 View.Gone 导致问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42949643/

相关文章:

android - 将 CardView 添加到布局时出错

java - 服务类中的 Spring Autowired 异常

java - 在X509TrustManager中,方法 "getAcceptedIssuers"有什么用?

java - 空无限循环和 GC (JVM)。请说明效果

java - 两个双核处理器系统的并行性

android - 有没有办法可视化使用 Android Studio 开发的 Flutter 应用程序中的特定 UI 元素?

android - Cordova 安卓支付插件

android - 将 setText 与有关当前时间的规则一起使用

xml - 检测 xml 中的间隙/第一个可用 ID :id sequence with XQuery/Xpath

c++ - 使用 libxml2 的 XML 解析结果重复