0
我正在使用自定義TabWidget來顯示我的標籤。當我第一次運行該程序時,這些標籤非常有用。一切看起來很美。但是,當我重新加載程序時,根據logcat,在我的Tab Widget上調用onResume()方法,TabWidget僅顯示Widget的上半部分。這是我的TabWidget的XML。標籤控件無法正確顯示onResume()
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@android:id/tabs"/>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="55dp"
android:layout_alignParentBottom="true" />
</RelativeLayout>
</TabHost>
這是很普通的香草的東西在這裏。改變layout_height並沒有幫助。
我目前沒有在我的TabWidget.java中實現onResume。但無論如何繼承了代碼。
public class TabWidget extends TabActivity {
private TabHost mTabHost;
private void setupTabHost() {
mTabHost = (TabHost) findViewById(android.R.id.tabhost);
mTabHost.setup();
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.tabs);
Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost); // The
// activity
// TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
setupTabHost();
// mTabHost.getTabWidget().setDividerDrawable(R.drawable.tab_divider);
// Dealer tab
Intent intentDealer = new Intent().setClass(this, DealerActivity.class);
int iconDealer = (R.drawable.ic_tab_dealer);
setupTab("Dealer", intentDealer, iconDealer);
// Department tab
Intent intentDept = new Intent().setClass(this, DeptActivity.class);
int iconDept = R.drawable.ic_tab_dept;
setupTab("Departments", intentDept, iconDept);
// PostBoard Activity
Intent intentBoard = new Intent().setClass(this, BoardActivity.class);
int iconBoard = R.drawable.ic_tab_board;
setupTab("Postboard", intentBoard, iconBoard);
// Social Network connection
// Check first to see if there are Social Network links if not don't
// show tab.
if (Startup.msMain.locations[Startup.nChosenLocation].social_media_feeds.length == 0) {
} else {
Intent intentSocial = new Intent().setClass(this,
SocialActivity.class);
int iconSocial = R.drawable.ic_tab_social;
setupTab("Social Media", intentSocial, iconSocial);
}
// Links Activity
Intent intentLinks = new Intent().setClass(this, LinksActivity.class);
int iconLinks = R.drawable.ic_tab_link;
setupTab("Links", intentLinks, iconLinks);
// set startup tab
tabHost.setCurrentTab(0);
}
private void setupTab(final String tag, Intent intent, int img) {
View tabview = createTabView(mTabHost.getContext(), tag, img);
TabSpec setContent = mTabHost.newTabSpec(tag).setIndicator(tabview)
.setContent(intent);
mTabHost.addTab(setContent);
}
private static View createTabView(final Context context, final String text,
int img) {
View view = LayoutInflater.from(context)
.inflate(R.layout.tabs_bg, null);
TextView tv = (TextView) view.findViewById(R.id.tabsText);
tv.setText(text);
ImageView icon = (ImageView) view.findViewById(R.id.tabsIcon);
icon.setBackgroundDrawable(context.getResources().getDrawable(img));
return view;
}
}
而爲了徹底,這裏是我的logcat出現錯誤時。
12-28 10:10:00.963: I/ActivityManager(1305): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.zocalolabs.demo/.SplashScreen } from pid 1470
12-28 10:10:01.034: W/InputManagerService(1305): Starting input on non-focused client [email protected] (uid=10001 pid=1470)
12-28 10:10:01.073: I/ActivityManager(1305): Resumed Activity: com.zocalolabs.demo/.TabWidget totalTime: 110 ms
有沒有辦法迫使我的小部件活動重繪上的onResume(),或在onPause(),它強制全開從而殺死活動再次迫使到onCreate方法?還是有另一種方法來解決這個問題?感謝任何見解!
所以我想我沒有得到回答我自己的問題的積分,但事實證明,罪魁禍首實際上是 – Rymnel 2011-12-28 17:00:51
,如果你找到了自己的問題的答案,這是一個很好的做法,回答自己的問題,然後選擇它作爲正確的答案。不要害羞!這樣,如果有人發現你的問題/答案有幫助,他們可以投票給你,並給你信用。 http://meta.stackexchange.com/questions/12513/should-i-not-answer-my-own-questions – Aurora 2012-01-19 18:09:42
謝謝。我繼續前進,並將其轉移到一個答案。 – Rymnel 2012-01-23 19:05:10