【问题标题】:xml saves without errors, but then has an error a few minutes laterxml保存没有错误,但几分钟后出现错误
【发布时间】:2015-02-23 07:29:32
【问题描述】:

我编写的这个 xml 文件保存时没有错误,并在 eclipse 的预览中准确地显示了我期望它的样子。但是如果有足够的时间(大约 5-10 分钟),在继续处理项目的其他部分(如实际的 Java 文件)后,此文件会引发错误。

它在抱怨,因为我正在锚定在 xml 文件中进一步声明的视图上。但我无法解决这个问题,因为所有 3 个主要部分都相互依赖。如果我改变它,它看起来一点也不好看。

我该如何解决这个问题?

<!-- The chat bubble -->
<RelativeLayout
    android:id="@+id/chat_bubble_wrapper"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="5dp">

    <!-- The user's name above the chat bubble -->
    <TextView 
        android:id="@+id/chat_bubble_username"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@id/chat_bubble_comment"  ERROR HERE!!!!
        android:layout_marginLeft="9dip"
        android:textSize="12sp"
        android:text="Username"
        android:textColor="#88000000">
        </TextView>

    <TextView
        android:id="@+id/chat_bubble_comment"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/chat_bubble_username"            
        android:layout_toRightOf="@id/chat_bubble_profile_picture" 
        android:layout_margin="5dip"
        android:background="@drawable/bubble_yellow"
        android:paddingLeft="4dp"
        android:text="Hello bubbles!"
        android:textColor="@android:color/primary_text_light" />

     <!--  The user's profile picture next to the chat bubble -->
    <ImageView 
        android:id="@+id/chat_bubble_profile_picture"
        android:layout_marginLeft="10dip"
        android:layout_width="32dp"
        android:layout_height="32dp"
        android:background="#000000"
        android:layout_alignTop="@id/chat_bubble_comment"
        />



</RelativeLayout>

【问题讨论】:

    标签: android xml eclipse


    【解决方案1】:

    改变

    android:layout_alignLeft="@id/chat_bubble_comment"
    

    android:layout_alignLeft="=@+id/chat_bubble_comment"  
    

    【讨论】:

    • 我认为+@id/chat_bubble_comment应该@+id/chat_bubble_comment
    • @Fahim 哇,我不知道你能做到。我应该保留所有的 id 属性(带有加号)吗?我不完全确定加号现在是如何工作的(你有点颠覆了我的世界)。我还需要为中间元素中的layout_toRightOf 属性执行此操作。如果它在接下来的 15 分钟左右没有随机决定抛出错误,我会接受这个答案。
    • 只要你使用@id/,把它改成@+id/
    • @Fahim 这解释了它:developer.android.com/guide/topics/ui/declaring-layout.html 我第一次使用 id 时,我必须用加号创建它。之后每次使用 id 时,我都可以省略加号,因为我只是引用它而不是创建它。所以我应该去掉第二个和第三个元素的 id 属性中的加号。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-21
    • 1970-01-01
    • 2011-12-22
    • 1970-01-01
    • 1970-01-01
    • 2017-11-15
    • 1970-01-01
    相关资源
    最近更新 更多