我的应用程序在添加android:layout_below后崩溃了

时间:2013-12-18 11:19:37

标签: android

我需要帮助添加android:layout_below并在成功添加后现在我的应用程序崩溃,当我开始看到结果我希望你帮助我这是我的代码

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip" >

<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/secondLine"
android:layout_alignParentLeft="true"
android:gravity="center_vertical"
android:text="@string/state1"
android:textSize="16sp" />


<TextView
android:id="@+id/secondLine"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_below="@id/textView1"
android:ellipsize="marquee"
android:singleLine="true"
android:text="@string/sayer1"
android:textSize="12sp" />

</RelativeLayout>

这是我的logcat

12-18 13:57:18.581: D/AndroidRuntime(2237): Shutting down VM
12-18 13:57:18.581: W/dalvikvm(2237): threadid=1: thread exiting with uncaught exception (group=0x411e62a0)
12-18 13:57:18.581: E/AndroidRuntime(2237): FATAL EXCEPTION: main
12-18 13:57:18.581: E/AndroidRuntime(2237): java.lang.IllegalStateException: Circular dependencies cannot exist in RelativeLayout
12-18 13:57:18.581: E/AndroidRuntime(2237):     at android.widget.RelativeLayout$DependencyGraph.getSortedViews(RelativeLayout.java:1321)
12-18 13:57:18.581: E/AndroidRuntime(2237):     at android.widget.RelativeLayout.sortChildren(RelativeLayout.java:316)
12-18 13:57:18.581: E/AndroidRuntime(2237):     at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:337)
12-18 13:57:18.581: E/AndroidRuntime(2237):     at android.view.View.measure(View.java:15481)
12-18 13:57:18.581: E/AndroidRuntime(2237):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5107)
12-18 13:57:18.581: E/AndroidRuntime(2237):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
12-18 13:57:18.581: E/AndroidRuntime(2237):     at android.view.View.measure(View.java:15481)
12-18 13:57:18.581: E/AndroidRuntime(2237):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:833)
12-18 13:57:18.581: E/AndroidRuntime(2237):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
12-18 13:57:18.581: E/AndroidRuntime(2237):     at android.view.View.measure(View.java:15481)
12-18 13:57:18.581: E/AndroidRuntime(2237):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5107)
12-18 13:57:18.581: E/AndroidRuntime(2237):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
12-18 13:57:18.581: E/AndroidRuntime(2237):     at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2361)
12-18 13:57:18.581: E/AndroidRuntime(2237):     at android.view.View.measure(View.java:15481)
12-18 13:57:18.581: E/AndroidRuntime(2237):     at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1999)
12-18 13:57:18.581: E/AndroidRuntime(2237):     at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1238)
12-18 13:57:18.581: E/AndroidRuntime(2237):     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1413)
12-18 13:57:18.581: E/AndroidRuntime(2237):     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1131)
12-18 13:57:18.581: E/AndroidRuntime(2237):     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4611)
12-18 13:57:18.581: E/AndroidRuntime(2237):     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
12-18 13:57:18.581: E/AndroidRuntime(2237):     at android.view.Choreographer.doCallbacks(Choreographer.java:555)
12-18 13:57:18.581: E/AndroidRuntime(2237):     at android.view.Choreographer.doFrame(Choreographer.java:525)
12-18 13:57:18.581: E/AndroidRuntime(2237):     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
12-18 13:57:18.581: E/AndroidRuntime(2237):     at android.os.Handler.handleCallback(Handler.java:615)
12-18 13:57:18.581: E/AndroidRuntime(2237):     at android.os.Handler.dispatchMessage(Handler.java:92)
12-18 13:57:18.581: E/AndroidRuntime(2237):     at android.os.Looper.loop(Looper.java:137)
12-18 13:57:18.581: E/AndroidRuntime(2237):     at android.app.ActivityThread.main(ActivityThread.java:4898)
12-18 13:57:18.581: E/AndroidRuntime(2237):     at java.lang.reflect.Method.invokeNative(Native Method)
12-18 13:57:18.581: E/AndroidRuntime(2237):     at java.lang.reflect.Method.invoke(Method.java:511)
12-18 13:57:18.581: E/AndroidRuntime(2237):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
12-18 13:57:18.581: E/AndroidRuntime(2237):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
12-18 13:57:18.581: E/AndroidRuntime(2237):     at dalvik.system.NativeStart.main(Native Method)

3 个答案:

答案 0 :(得分:2)

android:layout_alignBottom="@+id/secondLine" // remove this

for textview1

android:layout_below="@id/textView1" 

for textView2

原因

java.lang.IllegalStateException: Circular dependencies cannot exist in RelativeLayout

删除其中一个,它应该可以正常工作

将第TextViewsecondLine的{​​{1}}与TextView相对,ID为textview1。你有循环依赖,这是不可能的,因此错误。

您需要相对于另一个放置一次视图。

答案 1 :(得分:0)

您正在为textView1分配android:layout_alignBottom="@+id/secondLine" 在第二个TextView中,您要将secondLine分配给android:layout_below="@id/textView1"

这意味着您要将一个textview分配给另一个,而第二个分配给第一个。

这是creting循环依赖。

您无法协助TextView1 <--> TextView2个关联。你只能分配单面。

删除任一行。

android:layout_alignBottom="@+id/secondLine"

android:layout_below="@id/textView1"

答案 2 :(得分:0)

两个TextView都指向它们中的每一个,如 android:layout_alignBottom =“@ + id / secondLine” android:layout_below =“@ id / textView1”所以它形式像圆形循环,因此你得到错误。从第一个textview中删除 android:layout_alignBottom =“@ + id / secondLine”