gpt4 book ai didi

java - Android:RelativeLayout 中不能存在循环依赖

转载 作者:行者123 更新时间:2023-11-30 00:36:47 30 4
gpt4 key购买 nike

以前可以工作的布局现在不行了。它是一个带有水平 ScrollView 的相对布局,但是当我创建这个 Activity 时,我完全弄乱了布局顺序,现在它不起作用了。我无法弄清楚为什么会出现此错误,而且我的 XML 代码一团糟,我为造成的困惑表示歉意。如果有人能解释问题是什么以及我如何解决它,我将不胜感激。

XML 代码:

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_rear_gunner"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.mr_br.ibcc_bomber_command.rear_gunner">


<HorizontalScrollView
android:id="@+id/horizontalScrollView1"
android:focusable="false"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:fillViewport="true"
>


<ImageView
android:id="@+id/scrollView"
android:layout_width="wrap_content" android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_toEndOf="@+id/enemy2"

android:layout_toRightOf="@+id/enemy2" android:scaleType="centerCrop"
app:srcCompat="@drawable/nightsky3"/>
</HorizontalScrollView>
<RelativeLayout
android:id="@+id/item_frame"
android:layout_width="2000dp"
android:layout_height="match_parent"
android:focusable="true"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.mr_br.ibcc_bomber_command.rear_gunner"
android:layout_alignParentTop="true" android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">

<TextView
android:id="@+id/textView2"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_alignParentEnd="true" android:layout_alignParentRight="true"
android:layout_alignParentTop="true" android:text="TextView"
android:textSize="36sp"/>
<TextView
android:id="@+id/score"
android:layout_width="220dp"
android:layout_height="wrap_content" android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" android:layout_alignParentTop="true"
android:layout_marginLeft="43dp" android:layout_marginStart="43dp"
android:layout_marginTop="14dp" android:focusable="false" android:text="Score:"
android:textColor="@android:color/background_dark"
android:textColorLink="?attr/colorPrimaryDark"
android:textSize="46sp"/>
<TextView
android:id="@+id/Health"
android:layout_width="400dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/score" android:layout_alignBottom="@+id/score"
android:layout_toEndOf="@+id/enemy2" android:layout_toRightOf="@+id/enemy2"
android:text="TextView" android:textColor="@android:color/background_dark"
android:textColorLink="?attr/colorPrimaryDark"
android:textSize="46sp"/>
<Button
android:id="@+id/btnPilot"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:onClick="pilotBonus"
android:text="Call Pilot Maneuver (Right)" android:layout_below="@+id/powerUps"
android:layout_alignLeft="@+id/btnPilotL" android:layout_alignStart="@+id/btnPilotL"/>
<Button
android:id="@+id/btnPilotL"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_marginLeft="11dp"
android:layout_marginStart="11dp" android:onClick="pilotBonus"
android:text="Call Pilot Maneuver (Left)" android:layout_below="@+id/btnPilot"
android:layout_alignParentLeft="true" android:layout_alignParentStart="true"/>
<TextView
android:id="@+id/ammo"
android:layout_width="350dp"
android:layout_height="wrap_content"
android:focusable="false"
android:text="Ammunition:"
android:textColor="@android:color/background_dark"
android:textColorLink="?attr/colorPrimaryDark"
android:textSize="46sp"
android:layout_marginRight="49dp" android:layout_marginEnd="49dp"
android:layout_alignTop="@+id/powerUps" android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"/>
<ImageView
android:id="@+id/reinforce3"
android:layout_width="150dp" android:layout_height="150dp"
android:scaleX="-1" android:visibility="invisible"
app:srcCompat="@drawable/bomber_neutral_info" android:layout_above="@+id/powerUps"
android:layout_alignParentLeft="true" android:layout_alignParentStart="true"/>
<ImageView
android:id="@+id/reinforce1"
android:layout_width="150dp" android:layout_height="150dp"
android:layout_marginTop="20dp" android:scaleX="-1"
android:visibility="invisible" app:srcCompat="@drawable/bomber_neutral_info"
android:layout_below="@+id/score" android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
<ImageView
android:id="@+id/reinforce2"
android:layout_width="150dp" android:layout_height="150dp"
android:scaleX="-1"
android:visibility="invisible" app:srcCompat="@drawable/bomber_neutral_info"
android:layout_below="@+id/reinforce1" android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
<ImageView
android:id="@+id/enemyblah"
android:layout_width="150dp" android:layout_height="150dp"
android:visibility="invisible" app:srcCompat="@drawable/bomber_neutral_info"
android:layout_marginTop="22dp" android:layout_alignTop="@+id/reinforce1"
android:layout_toRightOf="@+id/reinforce1" android:layout_toEndOf="@+id/reinforce1"/>
<ImageView
android:id="@+id/enemy4"
android:layout_width="150dp" android:layout_height="150dp"
android:layout_marginTop="30dp"
android:visibility="invisible" app:srcCompat="@drawable/bomber_neutral_info"
android:layout_below="@+id/enemy2" android:layout_toRightOf="@+id/enemy2"
android:layout_toEndOf="@+id/enemy2" android:layout_marginLeft="26dp"
android:layout_marginStart="26dp"/>
<TextView
android:id="@+id/powerUps"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:text="Support Calls Avaliable:"
android:textColor="@android:color/background_dark" android:textColorLink="?attr/colorPrimaryDark"
android:textSize="40sp"
android:layout_marginTop="33dp" android:layout_below="@+id/enemy3"
android:layout_alignLeft="@+id/btnPilot" android:layout_alignStart="@+id/btnPilot"/>
<Button
android:id="@+id/btnReinforce"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="opBonus" android:text="Operator Request Support"
android:layout_marginTop="15dp" android:layout_below="@+id/ammo"
android:layout_toRightOf="@+id/enemy2" android:layout_toEndOf="@+id/enemy2"/>
<Button
android:id="@+id/ammoR"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="Ammo" android:text="Ammo Request Support"
android:layout_alignBaseline="@+id/btnReinforce"
android:layout_alignBottom="@+id/btnReinforce" android:layout_alignLeft="@+id/enemy2"
android:layout_alignStart="@+id/enemy2" android:layout_marginLeft="17dp"
android:layout_marginStart="17dp"/>
<ImageView
android:id="@+id/enemy5"
android:layout_width="150dp" android:layout_height="150dp"
android:visibility="invisible" app:srcCompat="@drawable/bomber_neutral_info"
android:layout_above="@+id/ammo" android:layout_alignRight="@+id/ammoR"
android:layout_alignEnd="@+id/ammoR" android:layout_marginRight="19dp"
android:layout_marginEnd="19dp"/>
<ImageView
android:id="@+id/enemy6"
android:layout_width="150dp" android:layout_height="150dp"
android:visibility="invisible" app:srcCompat="@drawable/bomber_neutral_info"
android:layout_alignTop="@+id/enemy2" android:layout_alignRight="@+id/btnReinforce"
android:layout_alignEnd="@+id/btnReinforce" android:layout_marginRight="23dp"
android:layout_marginEnd="23dp"/>
<ImageView
android:id="@+id/enemy3"
android:layout_width="150dp" android:layout_height="150dp"
android:layout_marginTop="21dp" android:visibility="invisible"
app:srcCompat="@drawable/bomber_neutral_info"
android:layout_below="@+id/enemy2" android:layout_toLeftOf="@+id/enemy6"
android:layout_toStartOf="@+id/enemy6"/>
<ImageView
android:id="@+id/enemy2"
android:layout_width="300dp" android:layout_height="200dp"
android:layout_marginLeft="13dp" android:layout_marginStart="13dp"
android:visibility="invisible" app:srcCompat="@drawable/bomber_neutral_info"
android:layout_alignTop="@+id/enemyblah" android:layout_toRightOf="@+id/btnReinforce"
android:layout_toEndOf="@+id/btnReinforce"/>
<TextView
android:id="@+id/warning"
android:layout_width="400dp"
android:layout_height="wrap_content"
android:text="TextView" android:textColor="@android:color/holo_red_dark"
android:textColorLink="?attr/colorPrimaryDark"
android:textSize="46sp" android:layout_above="@+id/reinforce3"
android:layout_centerHorizontal="true" android:visibility="invisible"/>
</RelativeLayout>

错误:

enter image description here

最佳答案

根据 enemy2(位于内部 relativelayout 中),您有外部 relativelayout 的 imageview。这就是问题

关于java - Android:RelativeLayout 中不能存在循环依赖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43302335/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com