动态生成控件并设置布局参数
2017-01-18 20:16
417 查看
private final Button mBlankTab; protected LinearLayout.LayoutParams mBlankBtnParam=null; mBlankTab=new Button(AbsBaseActivity.this); mBlankTab.setBackgroundDrawable(getResources().getDrawable(R.drawable.fm_blank_tab)); mBlankBtnParam=new LinearLayout.LayoutParams( new ViewGroup.MarginLayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT)); mBlankTab.setLayoutParams(mBlankBtnParam); if(getViewDirection()==ViewGroup.LAYOUT_DIRECTION_LTR){ mBlankBtnParam.setMargins((int)getResources().getDimension(R.dimen.tab_margin_left),0, (int)getResources().getDimension(R.dimen.tabb_marfin_right),0);//左上右下 }else if(getViewDirection()==ViewGroup.LAYOUT_DIRECTION_RTL){ mBlankBtnParam.setMargins((int)getResources().getDimension(R.dimen.tabb_marfin_right),0, (int)getResources().getDimension(R.dimen.tab_margin_left),0); } mBlankTab.setLayoutParams(mBlankBtnParam); protected void addTab(String text){ LinearLayout.LayoutParams mlp=null; mlp=new LinearLayout.LayoutParams(new ViewGroup.MarginLayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT)); TextView txt=new TextView(AbsBaseActivity.this); txt.setTextColor(getResources().getColor(R.color.zuk_gray)); txt.setText(text); txt.setTextSize(12f); txt.setGravity(Gravity.CENTER); Drawable rightIcon=getResources().getDrawable(R.drawable.zuk_tab_right); Drawable leftIcon=getResources().getDrawable(R.drawable.zuk_tab_left); rightIcon.setBounds(0,0,rightIcon.getMinimumWidth(),rightIcon.getMinimumHeight()); leftIcon.setBounds(0,0,leftIcon.getMinimumWidth(),leftIcon.getMinimumHeight()); txt.setCompoundDrawables(leftIcon,null,rightIcon,null); txt.setLayoutParams(mlp); viewLikeBtn=txt; viewLikeBtn.setOnClickListener(AbsBaseActivity.this); viewLikeBtn.setId(mTabNameList.size()); mTabNameList.add(text); viewLikeBtn.setOutlineProvider(null); } }
相关文章推荐
- Android在程序中动态生成控件,动态布局
- Android 动态布局 动态生成 销毁控件 改变控件的位置等
- android 动态设置控件的高度,使用对应布局中的dp值
- 代码中动态设置相对布局里控件的位置
- Android动态添加设置布局与控件的方法
- 动态设置Silverlight 初始化参数以及设置控件中设置默认.xaml 页面
- android 动态创建控件并设置布局
- 根据父布局的宽高,动态设置控件的宽高
- TextView 控件设置以及动态给布局添加控件
- 代码动态设置控件布局
- android代码中动态设置布局中控件的属性
- android 动态创建控件并设置布局
- Android动态布局,并动态为TextView控件设置drawableLeft、drawableRight等属性添加图标
- winfrom动态生成的combox控件 绑定数据源之后 无法设置默认值问题
- LayoutParams 动态设置布局参数
- Android 动态设置控件的布局
- 动态添加设置布局与控件
- Android动态布局,并动态为TextView控件设置drawableLeft、drawableRight等属性添加图标
- Android 动态生成复杂的布局(View布局的子控件含自己的点击事件)
- 动态生成控件(CButton, CComboBox, CTreeCtrl, CListCtrl, CTabCtrl, CEdit)、字体设置、常见设置