利用在线工具自动化生成findviewById

我们在编码的时候经常会用到findviewById,不厌其烦,我之前介绍过一个很取巧的方法,挺好用的,这里再贴一下:

public class KaleBaseActivity extends Activity {

    private String TAG = getClass().getSimpleName();

    public final <E extends View> E getView(int id) {
        try {
            return (E) findViewById(id);
        } catch (ClassCastException ex) {
            Log.e(TAG, "Could not cast View to concrete class.", ex);
            throw ex;
        }
    }
}

把这个写到activity的父类中,以后用getView就可以获得控件了。当然,如果你还是习惯findViewById,那么下面的两款工具绝对适合你。

通过xml布局来生成findviewById的界面

一、第一个简单好用的工具

http://android.lineten.net/layout.php

二、第二个稍微复杂,但功能强大的工具(推荐)

https://www.buzzingandroid.com/tools/android-layout-finder/

原文地址:https://www.cnblogs.com/tianzhijiexian/p/4458175.html