【问题标题】:java.lang.IllegalStateException: Circular dependencies cannot exist in RelativeLayout : XMLjava.lang.IllegalStateException:RelativeLayout 中不能存在循环依赖项:XML
【发布时间】:2017-08-14 07:36:39
【问题描述】:

我在 android xml 中遇到问题。我收到上面的错误,但根据我的我没有在我的 xml 中给出循环依赖项。我正在尝试从最后 1 小时开始修复它,但我无法完成它。我根据要求在上面和下面使用过。我在这里附上我的xml。让我知道是否有人可以指出我错在哪里。我的 XML 如下所示

<?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: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:background="@color/colorPrimary"
        android:id="@+id/pageNavCount"
        android:orientation="horizontal"
        android:layout_above="@+id/devider"
        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>

    <View
        android:id="@+id/devider"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_above="@+id/pageNavLayout"
        android:background="#ffffff" />

    <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>-->
        <TextView
            android:background="#ffffff"
            android:layout_width="1dp"
            android:layout_height="match_parent" />


        <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>

        <TextView
            android:background="#ffffff"
            android:layout_width="1dp"
            android:layout_height="match_parent" />

        <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>
        <TextView
            android:background="#ffffff"
            android:layout_width="1dp"
            android:layout_height="match_parent" />

        <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>
        <TextView
            android:background="#ffffff"
            android:layout_width="1dp"
            android:layout_height="match_parent" />

        <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"
        android:orientation="vertical">

    </LinearLayout>

</RelativeLayout>

非常感谢:)

【问题讨论】:

    标签: java android xml android-layout


    【解决方案1】:

    你在这里使用循环依赖:

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

    和

     <View
        android:id="@+id/devider"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_above="@+id/pageNavLayout"
        android:background="#ffffff" />
    

    【讨论】:

      【解决方案2】:

      您将 layout_above 和 layout_below 都放在仅放在上方或下方的扩展视图寻呼机中,然后尝试它会解决让我知道它是否得到解决

      【讨论】:

      • 是的......你是对的,我已经按照你所说的方式完成了......现在我面临着奇怪的问题。在上面的 xml 中,ll_adLayout_latest 是我从 java 中隐藏的 adview,称为 view.gone ...如果我隐藏它...底部工具栏将移至顶部,屏幕变为空白...您知道那里有什么问题吗?谢谢
      • 你可以发截图吗
      • 这个活动是否包含两个工具栏,一个在顶部,另一个在底部?如果是这样,请分享最新更改的代码
      • 是的......它包含两个工具栏......它与上面发布的相同,只是按照您在回答中的建议进行了更改
      • ok 只在所有地方使用下面的布局 不要使用上面的布局,这样一个视图将位于另一个视图下方,这样就不会发生重叠
      猜你喜欢
      • 2017-08-07
      • 2015-05-26
      • 2017-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-18
      • 2020-11-18
      相关资源
      最近更新 更多