以下代码可做参考, 主要是需要先removeAllViews(),在这里卡了会。
public class BottomBar extends LinearLayout {
private Context mContext;
public final static int ITEM_LAYOUT_COLLECT = 0;
public final static int ITEM_LAYOUT_REMIND = 1;
public final static int ITEM_LAYOUT_LOCK = 2;
public BottomBar(Context context) {
this(context, null);
}
public BottomBar(Context context, AttributeSet attrs) {
super(context, attrs);
mContext = context;
LayoutInflater.from(context).inflate(R.layout.suite_bottombar_home, this, true);
}
public void setHomeLayout() {
removeAllViews();
LayoutInflater.from(mContext).inflate(R.layout.suite_bottombar_home, this, true);
}
public void setItemLayout(int type) {
removeAllViews();
LayoutInflater.from(mContext).inflate(R.layout.suite_bottombar_item, this, true);
TextView textView = (TextView)findViewById(R.id.mytv_suite_bottombar_tips_ok);
switch (type) {
case ITEM_LAYOUT_COLLECT:
textView.setText(mContext.getResources().getString(R.string.suite_bottombar_tips_ok_collect));
break;
case ITEM_LAYOUT_REMIND:
textView.setText(mContext.getResources().getString(R.string.suite_bottombar_tips_ok_remind));
break;
case ITEM_LAYOUT_LOCK:
textView.setText(mContext.getResources().getString(R.string.suite_bottombar_tips_ok_lock));
break;
}
}
public void setRecordLayout() {
removeAllViews();
LayoutInflater.from(mContext).inflate(R.layout.suite_bottombar_record, this, true);
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)