【发布时间】:2011-08-01 21:47:09
【问题描述】:
我注意到 Android 开发中最乏味的部分之一是布局设计,即使使用布局构建器也是如此。
设置好图形,然后布局,和布局元素做变量关联很繁琐,比如ImageButton myButton = (ImageButton)findViewById(R.id.myButton);
在较大的布局中,跟踪这些可能会变得乏味(回忆元素的名称),然后需要以任何顺序添加更多变量会令人沮丧。
为了稍微缓解这种情况,如果我在 XML 中声明的所有 ID 都自动与其适当的变量相关联,并且所有这些数据类型都已包含在该类中,那将非常方便
有什么东西已经这样做了吗?
例如,如果我写
<ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/myButton" android:id="@+id/myButton"></ImageButton>
那么我希望包含此布局的类已经拥有
import android.ImageButton;
ImageButton myButton;
myButton = (ImageButton)findViewById(R.id.myButton);
这是要请求的设置还是功能?我用的是Eclipse IDE,会很方便
【问题讨论】:
-
不是我所知道的,但会很酷 - 也许写它? :)
-
当然,我从来没有做过自动编码监听器……我应该怎么开始? Android AVD 的那部分也会开源吗?
标签: android xml layout convenience-methods