接下来视图id作为Android中自定义属性 [英] Next view id as a custom attribute in android
问题描述
有关我的自定义视图我还定义了看法保持ID的自定义属性。它的格式是参考。
For my custom view I have also defined a custom attribute for keep id of the view. Its format is "reference".
在布局XML定义它像下面,有非常相似的的android:layout_below
ATTR
in layout xml it is defined like below, very similar with android:layout_below
attr
<mycustomview id="@+id/cv_1" xyz:nextviewId="@id/cv_2"... />
<mycustomview id="@+id/cv_2" xyz:nextviewId="@id/cv_3"... />
...
<LinearLayout ...>
<mycustomview id="@+id/cv_3" xyz:nextviewId="@id/cv_4"... />
</LinearLayout>
...
它给了我的错误,我想这是因为它是尚未宣布。
it gives me error I think it is because it is not declared yet.
任何建议访问类似这样的做法!
Any suggestion for accessing the next object similar to this approach!!!
我想用标签ATTR为下一个目标查找下一个与findByTag功能。这是一个好办法做到这一点。
I am thinking to use tag attr for the next object find the next one with findByTag function. Is this a good way to do it.
非常感谢。
推荐答案
您的XML更改为:
...
<mycustomview id="@+id/cv_1" xyz:nextviewId="@+id/cv_2"... />
<mycustomview id="@+id/cv_2" xyz:nextviewId="@+id/cv_3"... />
...
(注意 @ +在ID
nextviewId
)
这将在Android 1.6+(API级别4+)工作。正是同样的方法在 RelativeLayout的
取值使用。
This will work on Android 1.6+ (Api Level 4+). Exactly the same approach is used in RelativeLayout
s.
这篇关于接下来视图id作为Android中自定义属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!