Android for actionbar为选项卡提供自定义视图

Android for actionbar为选项卡提供自定义视图,android,android-tabs,Android,Android Tabs,我正在为操作栏中的选项卡提供自定义视图。但是操作栏选项卡仅显示图像视图,而不显示其下方的文本视图。有谁能说出问题出在哪里 活动代码 package com.example.actionbar; import android.os.Bundle; import android.app.ActionBar; import android.app.ActionBar.Tab; import android.app.ActionBar.TabListener; import android.app.A

我正在为操作栏中的选项卡提供自定义视图。但是操作栏选项卡仅显示图像视图,而不显示其下方的文本视图。有谁能说出问题出在哪里

活动代码

package com.example.actionbar;

import android.os.Bundle;
import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.ActionBar.TabListener;
import android.app.Activity;
import android.app.FragmentTransaction;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;

  public class MainActivity extends Activity implements TabListener {

private String tag = "MainActivity";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    try {
        ActionBar actionBar = getActionBar();
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

        Tab tab = actionBar.newTab();

        LayoutInflater inflator = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
        View view = inflator.inflate(R.layout.tabview, null);
        tab.setCustomView(view);
        tab.setTabListener(this);
        actionBar.addTab(tab);

        Tab tab1 = actionBar.newTab();

        View view1 = inflator.inflate(R.layout.tabview, null);
        tab1.setCustomView(view1);
        tab1.setTabListener(this);
        actionBar.addTab(tab1);

        Tab tab2 = actionBar.newTab();

        View view2 = inflator.inflate(R.layout.tabview, null);
        tab2.setCustomView(view2);
        tab2.setTabListener(this);
        actionBar.addTab(tab2);

        Tab tab3 = actionBar.newTab();

        View view3 = inflator.inflate(R.layout.tabview, null);
        tab3.setCustomView(view3);
        tab3.setTabListener(this);
        actionBar.addTab(tab3);
    } catch (Exception e) {

        Log.d(tag, "Exception...." + e);
    }
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public void onTabReselected(Tab arg0, FragmentTransaction arg1) {
    // TODO Auto-generated method stub

}

@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
    // TODO Auto-generated method stub

}

@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
    // TODO Auto-generated method stub

}
    }
为选项卡提供自定义视图的Xml代码

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:src="@drawable/ic_launcher" />


<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Ashish" 
  />

</LinearLayout>

android:layout\u gravity=center可能是问题所在。我不认为这是问题所在。将android:layout\u height=match\u父对象放入线性布局或更改方向。我猜文本视图隐藏在Imageview后面。那么解决方案是什么。