谁能告诉我如何在android的中心对齐标签文本?我已经放弃 android:gravity="center"
了LinearLayout
和TabWidget
。它仍然无法正常工作。谁能告诉我该怎么做?
谢谢
谁能告诉我如何在android的中心对齐标签文本?我已经放弃 android:gravity="center"
了LinearLayout
和TabWidget
。它仍然无法正常工作。谁能告诉我该怎么做?
谢谢
用这个
int tabCount = tabHost.getTabWidget().getTabCount();
for (int i = 0; i < tabCount; i++) {
final View view = tabHost.getTabWidget().getChildTabViewAt(i);
if ( view != null ) {
// reduce height of the tab
view.getLayoutParams().height *= 0.66;
// get title text view
final View textView = view.findViewById(android.R.id.title);
if ( textView instanceof TextView ) {
// just in case check the type
// center text
((TextView) textView).setGravity(Gravity.CENTER);
// wrap text
((TextView) textView).setSingleLine(false);
// explicitly set layout parameters
textView.getLayoutParams().height = ViewGroup.LayoutParams.FILL_PARENT;
textView.getLayoutParams().width = ViewGroup.LayoutParams.WRAP_CONTENT;
}
}
}
利用android:layout_gravity="center"