【发布时间】:2016-12-23 05:24:30
【问题描述】:
我无法将这 3 个按钮和 1 个编辑文本放在相关布局中。 基本上,我是顶部的列表视图,然后是列表视图下的相对视图。此相对视图将由第一行中的编辑文本和第二行中的 3 个按钮组成。
一切正常,但是,当我在相对布局中放置 1 个编辑文本和 3 个按钮时,出现错误 java.lang.IllegalStateException:RelativeLayout 中不能存在循环依赖
有人可以帮忙吗,非常感谢您的时间。 谢谢
<?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_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
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="app.com.date.MainActivity"
android:background="@color/common_google_signin_btn_text_light_disabled">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_above="@+id/messageBox"
android:id="@+id/chatroom"
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll"
android:dividerHeight="0dp"
android:divider="@null"
android:layout_alignParentBottom="false"
android:layout_alignWithParentIfMissing="false" />
<EditText
android:layout_width="match_parent"
android:inputType="text"
android:ems="10"
android:id="@+id/messageBox"
android:textAppearance="@style/TextAppearance.AppCompat"
android:freezesText="true"
android:textSize="12sp"
android:fontFamily="sans-serif"
android:layout_alignParentBottom="false"
android:layout_above="@+id/sendButton"
android:breakStrategy="high_quality"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:paddingBottom="15dip"
android:paddingTop="10dip"
android:hint="send message" />
<Button
android:id="@+id/galleryButton"
android:layout_below="@+id/messageBox"
android:layout_alignParentStart="false"
android:layout_alignParentBottom="false"
android:layout_width="50dip"
android:layout_height="wrap_content"
android:layout_centerHorizontal="false"
android:layout_alignParentLeft="true" />
<Button
android:id="@+id/cameraButton"
android:layout_below="@+id/messageBox"
android:layout_alignParentBottom="false"
android:layout_width="50dip"
android:layout_height="wrap_content"
android:layout_centerHorizontal="false"
android:layout_marginLeft="10dip"
android:layout_toRightOf="@+id/galleryButton" />
<Button
android:layout_height="wrap_content"
android:id="@+id/sendButton"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="15dip"
android:layout_width="75dip" />
</RelativeLayout>
【问题讨论】:
-
这段代码对我来说非常好用。当为彼此设置两个视图的引用时,就会出现循环依赖。说button1在button2的左边,button2在button1的右边。这会导致循环依赖错误。
-
这段代码很好,但我想把编辑文本和 3 按钮放在一个额外的相对布局中
-
外部相对布局 -- 列表视图 -- 内部相对布局(编辑文本,3 个按钮) -- 内部相对布局结束 -- 外部相对布局结束
-
您确切需要的布局是什么?可以发图或者画图吗?
标签: android