使用Kotin android 扩展我可以避免使用findViewById
,但我不确定如何命名 id 以正确使用它。
我发现两个选项是:
- 对 id 使用简单的名称,但如果我将其与片段一起使用,我可能会在使用 espresso 时遇到麻烦:
android.support.test.espresso.AmbiguousViewMatcherException: 'with id: .../mainLayout' 匹配层次结构中的多个视图。
这是因为我在 TabLayout 中有两个具有相同 id 的片段:
<LinearLayout android:id="@+id/mainLayout"
- 所有者姓名:
"@+id/loginMainLayout"
和"@+id/signUpMainLayout"
但后来我将不得不使用像signUpMainLayout.doSomething()
.
注意:我不喜欢
_
在这种情况下使用 ,因为这不是一个好的代码风格。
还有哪些其他选择?