2

谁能告诉我如何在android的中心对齐标签文本?我已经放弃 android:gravity="center"LinearLayoutTabWidget。它仍然无法正常工作。谁能告诉我该怎么做?

谢谢

4

2 回答 2

3

用这个

    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;
    }
}

}

于 2013-07-16T11:09:33.473 回答
0

利用android:layout_gravity="center"

于 2012-07-13T14:59:31.490 回答