Good morning Or afternoon.
I am trying to add a page with tabs in this app. Currently this app is divided into Fragments
with the top and bottom title bars in the activity.
This was fine for the rest of the app. Now I need to add a tab with both the bottom and top bars.
I have used JakeWharton/ViewPagerIndicator which worked perfect without the added navigation bars. But before the way the code was setup (before i came to the project) makes it Incredibly difficult to do this.
Not a problem I heard about Fragment Tab Host. So I got the fragment Tab Host working.
The problem with four tabs the text get squashed and wraps onto two line. I have searched may possible fixes including FragmentTabHost with horizontal scroll
However no matter what I try it just never seems to work.
Below is my Fragment
public class BPInformationFragment extends Fragment {
private FragmentTabHost tabHost;
private View v;
private OnRightMenuClickedListener mCallback;
public static BPInformationFragment newInstance() {
BPInformationFragment f = new BPInformationFragment();
return f;
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
mCallback = (OnRightMenuClickedListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString()
+ " must implement OnRightMenuClickedListener");
}
}
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setRetainInstance(false);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
v = inflater.inflate(R.layout.layout_information, container, false);
tabHost = new FragmentTabHost(getActivity()); tabHost.setup(getActivity(), getChildFragmentManager(),R.layout.layout_information);
Bundle arg1 = new Bundle();
arg1.putInt("Frag", 1);
tabHost.addTab(tabHost.newTabSpec("Tab1").setIndicator("Symptomsn Long title"),
InformationSymptomsFragment.class, null);
Bundle arg2 = new Bundle();
arg2.putInt("Frag1", 2);
tabHost.addTab(tabHost.newTabSpec("Tab2").setIndicator("StratagiesVerylong title"),
InformationStrategiesFragment.class, arg2);
Bundle arg3 = new Bundle();
arg3.putInt("Frag2", 3);
tabHost.addTab(tabHost.newTabSpec("Tab3").setIndicator("B-Safe"),
BPAboutFragment.class, arg3);
Bundle arg4 = new Bundle();
arg4.putInt("Frag3", 4);
tabHost.addTab(tabHost.newTabSpec("Tab4").setIndicator("Radar"),
BPMyAccountFragment.class, arg4);
TabWidget tw = (TabWidget)v.findViewById(android.R.id.tabs);
LinearLayout ll = (LinearLayout) tw.getParent();
HorizontalScrollView hs = new HorizontalScrollView(getActivity());
hs.setLayoutParams(new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.WRAP_CONTENT));
ll.addView(hs, 0);
ll.removeView(tw);
hs.addView(tw);
hs.setHorizontalScrollBarEnabled(false);
mCallback.setBottomButtons(DefinedConstants.MENU_INFORMATION);
return tabHost;
}
Below is my XML
<android.support.v4.app.FragmentTabHost 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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0" />
<FrameLayout
android:id="@+id/realtabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" />
</LinearLayout>
If anyone could help that would be amazing. Sorry for the long post.