Android学习笔记(五) 之android tabwidget 调整高度文字居中
处理如下:
[java]
<span style="font-size:18px;color:#3333ff;"> TabWidget tabWidget = tabHost.getTabWidget();
for (int i = 0; i < tabWidget.getChildCount(); i++) {
View child = tabWidget.getChildAt(i);
final TextView tv = (TextView)child.findViewById(android.R.id.title);
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) tv.getLayoutParams();
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, 0); //取消文字底边对齐
params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); //设置文字居中对齐
}</span>
但是这样高度不协调,然后需要调整高度,再更改代码
[java]
<span style="font-size:18px;color:#3333ff;"> TabWidget tabWidget = tabHost.getTabWidget();
for (int i = 0; i < tabWidget.getChildCount(); i++) {
View child = tabWidget.getChildAt(i);
final TextView tv = (TextView)child.findViewById(android.R.id.title);
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) tv.getLayoutParams();
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, 0); //取消文字底边对齐
params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); //设置文字居中对齐
child.getLayoutParams().height = 30;
// final ImageView iv = (ImageView)child
// .findViewById(android.R.id.icon);
// iv.getLayoutParams().height = 0;
}
</span>
补充:移动开发 , Android ,