开发者

RelativeLayout's layout_above gives "No resource found" error

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
  <ListView
      android:layout_above="@id/btn_4"    <-- this line error: No resource found
      android:layout_width="match_parent"
      android:layout_height="200dp" />
  <Button android:id="@+id/btn_4"         <-- I declare the id here
      android:layout_alignParentBottom="true"
      android:layout_height="wrap_content"
      android:layout_width="match_parent" />
</Rela开发者_开发问答tiveLayout>

Any suggestions?


As I understand it, the first time an id is used in a layout xml, it needs to have a + sign in front of it.

From the Declaring Layout docs:

The plus-symbol (+) means that this is a new resource name that must be created and added to our resources (in the R.java file).

So, add a '+' to the first btn_4 reference in the ListView layout and you can remove the unnecessary '+' from the android:id attribute in the Button layout.


When you declare relative layouts, you have to use android:layout_above="@+id/layoutToBeAbove"

Otherwise, the system does not know what you're pointing at.

This declaration will point at the same resource.

Hope this helped!


Declare the ListView list_1 after declaring the Button btn_4 as it tries to reference it in android:layout_above="@id/btn_4".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜