【问题标题】:View.Gone of ParentBottom view is causing issueView.Gone of ParentBottom 视图导致问题
【发布时间】:2017-03-22 10:58:17
【问题描述】:

我有一个照片应用程序,我在屏幕底部显示 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>

【问题讨论】:

    标签: java android xml android-layout


    【解决方案1】:

    那是因为你有

    <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 从未存在过,它会保留您已建立的依赖关系。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-04-05
      • 1970-01-01
      • 1970-01-01
      • 2015-02-04
      • 1970-01-01
      • 1970-01-01
      • 2014-01-30
      相关资源
      最近更新 更多