渲染期间引发异常:RelativeLayout中不存在循环依赖
错误显示 渲染期间引发异常:RelativeLayout
中不存在循环依赖关系我应该怎么做才能解决此错误我尝试了不同的方法,但没有解决此问题
<RelativeLayout
android:id="@+id/mainHeader"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/driverPassengerName1"
android:layout_width="60px"
android:layout_height="90px"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@+id/driverPassengerName"
android:layout_toRightOf="@+id/driverRideDetailBtn"
android:background="@color/second_interaction_eighty_percent_opaque_color"
android:gravity="center"
android:singleLine="false"
android:text="Tariq Road Lahore"
android:textColor="@color/white"
android:textSize="40px" />
<TextView
android:id="@+id/driverPassengerName"
android:layout_width="100dp"
android:layout_height="90px"
android:layout_alignParentTop="true"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:layout_toLeftOf="@+id/driverCancelRideBtn"
android:layout_toRightOf="@+id/driverPassengerName1"
android:background="@color/second_interaction_eighty_percent_opaque_color"
android:gravity="center"
android:singleLine="false"
android:text="2222222222222222222222"
android:textColor="@color/white"
android:textSize="40px" />
<Button
android:id="@+id/driverCancelRideBtn"
android:layout_width="wrap_content"
android:layout_height="70px"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="@color/decline_color"
android:padding="5px"
android:text="@string/cancel_ride"
android:textColor="@color/white"
android:textSize="18px"
android:visibility="visible" />
<ImageButton
android:id="@+id/driverRideDetailBtn"
android:layout_width="60px"
android:layout_height="60px"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:background="@drawable/home"
android:visibility="visible" />
</RelativeLayout>
答案 0 :(得分:2)
我无法理解为什么你的实施变得复杂。在您的所有观点中,您都提到了layout_alignParentTop="true"
。另外,我可以看到你只想连续形成视图。从您的视图中删除依赖项toLeftOf
和toRightOf
,并将您的视图移至LinearLayout
。
您的实施应该是这样的:
<LinearLayout
android:id="@+id/mainHeader"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageButton
android:id="@+id/driverRideDetailBtn"
android:layout_width="60px"
android:layout_height="60px"
android:background="@drawable/home"
android:visibility="visible" />
<TextView
android:id="@+id/driverPassengerName"
android:layout_width="100dp"
android:layout_height="90px"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:background="@color/second_interaction_eighty_percent_opaque_color"
android:gravity="center"
android:singleLine="false"
android:text="2222222222222222222222"
android:textColor="@color/white"
android:textSize="40px" />
<TextView
android:id="@+id/driverPassengerName1"
android:layout_width="60px"
android:layout_height="90px"
android:background="@color/second_interaction_eighty_percent_opaque_color"
android:gravity="center"
android:singleLine="false"
android:text="Tariq Road Lahore"
android:textColor="@color/white"
android:textSize="40px" />
<Button
android:id="@+id/driverCancelRideBtn"
android:layout_width="wrap_content"
android:layout_height="70px"
android:background="@color/decline_color"
android:padding="5px"
android:text="@string/cancel_ride"
android:textColor="@color/white"
android:textSize="18px"
android:visibility="visible" />
</LinearLayout>
希望有所帮助:)
答案 1 :(得分:0)
您告诉RelativeLayout
保留driverPassengerName1 TextView
toLeft
的{{1}} driverPassengerName
&amp; TextView
要driverPassengerName
rightOf
!这当然是循环依赖。请删除一个,删除
driverPassengerName1
来自First TextView
或
android:layout_toLeftOf="@+id/driverPassengerName"
来自Second TextView的