issue with “@id” vs “@+id” in positioning in Relative Layout

前端 未结 3 612
忘掉有多难
忘掉有多难 2020-12-01 23:56

Good day, i have a slight issue with relative layouts and i don\'t know why. Normally when you trying to position relative to other views, you use \"@id\" but it doesn\'t se

3条回答
  •  猫巷女王i
    2020-12-02 00:02

    Although you can refer to views declared later in the hierarchy, the XML document is still parsed sequentially. The first time that you refer to a particular ID, you have to prefix it with @+id. In actuality, you can prefix every reference to an ID with @+id and everything will work -- in fact, this is what happens if you design your interface with the graphical editor. Just to be safe, everything is prefixed with @+id. The + simply tells it to generate an ID in R.java if and only if it has not already been defined. If you try to define it more than once, it just sees that it's already been defined and continues on normally.

    In your XML, you reference imagearrow_id from your percentage_id TextView. However, at this point the imagearrow_id has not yet been defined. For this scenario, you could simply prefix the layout_toLeftOf=@+id/imagearrow_id in your TextView, and then below, when defining your ImageView (imagearrow_id), you would not need the + in the android:id attribute.

提交回复
热议问题