आदेश आसानी से टुकड़े के बीच स्विच करने के लिए, मैं बहुत तरह मेरे टैब लेआउट में एक HorizontalScrollView embedding हूँ:TabHost में HorizontalScrollView अंत पर अतिरिक्त स्थान जोड़ने
<?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="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbars="none" >
<TabWidget android:id="@android:id/tabs"
android:layout_height="wrap_content"
android:layout_width="wrap_content">
</TabWidget>
</HorizontalScrollView>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</TabHost>
लेकिन मेरे कोड में टुकड़े जोड़ने के बाद (नीचे दिखाया गया
स्क्रॉल
से पहले:) वहाँ अचानक HorizontalScrollView के अंत में कुछ अतिरिक्त व्हाइट दिखाता हैस्क्रॉल
के बाद कोड काफी जटिल है, लेकिन मैं महत्वपूर्ण भागों दिखाने का प्रयास करेंगे।
{
mTabHost = (TabHost) childLayout.findViewById(android.R.id.tabhost);
mTabHost.setup();
FrameLayout tabsFL = (FrameLayout) childLayout.findViewById(android.R.id.tabcontent);
tabsFL.setId(TABS_FRAME_ID);
for (int i = 0; i < list.size(); i++) {
mTabHost.addTab(newTab(String.valueOf(i), list.get(i).getTitle(), tabsFL.getId()));
}
mTabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
@Override
public void onTabChanged(String tabId) {
updateTab(tabId, Integer.parseInt(tabId), list);
}
});
//manually load first fragment
mTabHost.setCurrentTab(mCurrentTab);
updateTab(String.valueOf(mCurrentTab), mCurrentTab, list);
}
private TabSpec newTab(String tag, String tabLabel, int tabContentId) {
int count = Integer.parseInt(tag);
count +=1;
View indicator = inflater.inflate(R.layout.details_tab,
(ViewGroup) childLayout.findViewById(android.R.id.tabs), false);
((TextView) indicator.findViewById(R.id.text)).setText(count + ". " + tabLabel);
TabSpec tabSpec = mTabHost.newTabSpec(tag);
tabSpec.setIndicator(indicator);
tabSpec.setContent(tabContentId);
return tabSpec;
}
private void updateTab(String tabId, int id, ArrayList<CustomObject> frags) {
mCurrentTab = id;
FragmentManager fm = activity.getSupportFragmentManager();
fm.beginTransaction()
.replace(TABS_FRAME_ID, DetailsFragment.newInstance(frags.get(id)), tabId)
.commitAllowingStateLoss();
}
इसके अलावा असंबंधित, लेकिन मैं भी एक समस्या है, जहां पहले टैब मैन्युअल रूप से लोड नहीं करता है (टैब पर क्लिक टुकड़े पूरी तरह से लोड करता है, बस बहुत पहले एक किसी कारण से लोड नहीं करता है)।
यह 'एंड्रॉयड की वजह से हो सकता है: fillViewport =" true "' 'HorizontalScrollView' में, एक उदाहरण के लिए इसे हटाने के लिए कोशिश करते हैं और देखें कि यह काम करता है या नहीं। 'क्षैतिज स्क्रॉलव्यू' और 'टैबविड्ज' दोनों में 'android: layout_height =" wrap_content "है, इसलिए' fillViewport' कारण हो सकता है। – g00dy
दुर्भाग्य से मैंने कोशिश की और इससे कोई फर्क नहीं पड़ता। मैंने सोचा कि शायद मैं गलती से अतिरिक्त (अदृश्य?) टैब जोड़ रहा हूं, लेकिन यह नहीं पता कि लॉग स्टेटमेंट के साथ यह कहां हो सकता है। –
शायद यह 'टैबएसएफएल' के अंदर है? मुझे नहीं पता, लेकिन शायद आखिरी टैब आधा अदृश्य है, एक भी चेक करें :) – g00dy