我想构建一个Tab
视图,其中包含ImageView
和TextView
。我会编写一个名为Tab
的类LinearLayout
。
和我在代码中的困惑。
public Tab(Context context, AttributeSet attrs) {
super(context, attrs);
//-----is necessary?
//removeAllViews();
this.context = context;
this.layoutInflater = (LayoutInflater) this.context.getSystemService(Service.LAYOUT_INFLATER_SERVICE);
//-----what's different?
//View v = this.layoutInflater.inflate(R.layout.tab, this, true);
View v = this.layoutInflater.inflate(R.layout.tab, null);
//-----which one is right?
//this.iv = new ImageView(context, attrs);
//this.tv = new TextView(context, attrs);
//this.iv = (ImageView)v.findViewById(R.id.tab_icon);
//this.tv = (TextView)v.findViewById(R.id.tab_text);
//-----is necessary?
//addView(this.iv);
//addView(this.tv);
}