【问题标题】:Relative layout: align by element below, not found id相对布局:按以下元素对齐,未找到 id
【发布时间】:2016-12-23 08:37:24
【问题描述】:

我有 2 个两个按钮。我需要与下面的按钮对齐更高的按钮。

<Button
    android:text="@string/menu_start"
    android:layout_centerHorizontal="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="70dp"
    android:layout_alignLeft="@id/btn_menu_scores"
    android:layout_alignRight="@id/btn_menu_scores"
    android:textSize="30dp"
    android:textStyle="bold"
    android:layout_marginBottom="20dp"
    android:id="@+id/btn_menu_start"
    />
<Button
    android:text="@string/menu_scores"
    android:layout_gravity="center_horizontal"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textStyle="bold"
    android:textSize="30dp"
    android:layout_marginBottom="20dp"
    android:id="@+id/btn_menu_scores"/>

错误:(20, 35) 未找到与给定名称匹配的资源(位于“layout_alignLeft”,值为“@id/btn_menu_scores”)。

这段代码不起作用,如何解决这个问题?

【问题讨论】:

  • 更改顺序。先声明 menu_scores

标签: android alignment android-relativelayout


【解决方案1】:

使用 @+id/btn_menu_scores 而不是 @id/btn_menu_scores 作为 View 的 id:

android:layout_alignLeft="@+id/btn_menu_scores"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多