我可以使用的Andr​​oid相同的ID在不同的布局? [英] Can I use the same id in different layout in Android?

查看:182
本文介绍了我可以使用的Andr​​oid相同的ID在不同的布局?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的Andr​​oid开发。它是蛮好用的同一个ID在不同的布局 XML文件,图像和 TextViews

I am new to Android development. Is it fine to use the same ID for images and TextViews in different Layout XML files?

在日食自动列出它们对我来说,它列出了从项目中的所有布局变量,因此将它碰撞?到目前为止我还没有发现使用不同的布局相同ID的任何问题,但我担心的长远发展。

When eclipse auto-list them for me, it lists all the layout variables from the project, so will it collide? Till now I have not noticed any problems using the same ID in different layouts, but I am concerned in long run.

推荐答案

建议您使用不同的ID针对不同的布局。从长远来看,当你将有很多的布局,并为此大量的ID就会变得非常复杂,区分它们。

It is recommended that you use different ids for different layouts. On the long run, when you will have a lot of layouts and therefor a lot of ids it will get very complicated to differentiate them.

我通常命名我的id是这样的: layoutName_elementId

I usually name my ids like this: layoutName_elementId.

这对我的作品很容易地找到了ID,我要找的,尤其是当使用自动完成(我知道什么布局我的工作,但我真的不知道该ID;在这种情况下,我命名战略,我只输入布局的名称和它带来的是布局的所有IDS)。

It works for me to easily find the id I'm looking for, especially when using autocomplete (I know on what layout I'm working, but I don't really know the id; in this case, with my naming strategy, I only type the layout name and it brings on all the ids of that layout).

在布局和标识的更多信息可以在这里找到

More information on layouts and ids can be found here.

快乐编码,

这篇关于我可以使用的Andr​​oid相同的ID在不同的布局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆