我有一个照片应用程序,我在屏幕底部显示 admob 横幅。我从 java 管理它,并在需要时隐藏它。当我显示如下广告时,它工作正常
但是当我隐藏横幅时......底部导航工具栏位于顶部,屏幕显示空白,如下所示
我的 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
根本不在布局中一样。
您可以执行这两件事之一(或两者都执行,具体取决于您最终需要的行为。)。
- 将布局设置为不依赖于
ll_adLayout_latest
的位置。
- 使用
View.INVISIBLE
而不是 View.GONE
使用View.INVISIBLE
时,布局不会表现得好像ll_adLayout_latest
从未存在过一样,它将保留您已建立的依赖关系。
我是一名优秀的程序员,十分优秀!