Я испытываю странное поведение в таботе на разных устройствах. Это заставляет меня думать, что есть проблема с устройством (учитывая тот факт, что у меня возникают проблемы с запуском неофициального мода), но я решил все равно спросить.
Мои вкладки находятся в HorizontalScrollView с намерением, чтобы они простирались за выделенное пространство, но позволяли пользователю достигать их.
Вот мой код
Активность
// Set up Tabs
TabHost tabs = (TabHost)findViewById(R.id.my_tabhost);
tabs.setup();
TabSpec tspec1 = tabs.newTabSpec("items");
tspec1.setIndicator(makeTabView("Items", res.getDrawable(R.drawable.basket_icon_light)));
tspec1.setContent(R.id.tab1);
tabs.addTab(tspec1);
TabSpec tspec2 = tabs.newTabSpec("customers");
tspec2.setIndicator(makeTabView("Customers", res.getDrawable(R.drawable.customer_icon_light)));
tspec2.setContent(R.id.tab2);
tabs.addTab(tspec2);
TabSpec tspec3 = tabs.newTabSpec("dept");
tspec3.setIndicator(makeTabView("Departments", res.getDrawable(R.drawable.dept_icon_light)));
tspec3.setContent(R.id.tab3);
tabs.addTab(tspec3);
TabSpec tspec4 = tabs.newTabSpec("users");
tspec4.setIndicator(makeTabView("Users", res.getDrawable(R.drawable.user_icon_light)));
tspec4.setContent(R.id.tab4);
tabs.addTab(tspec4);
tabs.setOnTabChangedListener(tabchange);
TabSpec tspec5 = tabs.newTabSpec("terms");
tspec5.setIndicator(makeTabView("Terms", res.getDrawable(R.drawable.terms_icon_light)));
tspec5.setContent(R.id.tab5);
tabs.addTab(tspec5);
tabs.setOnTabChangedListener(tabchange);
private View makeTabView(String name, Drawable draw){
View v = View.inflate(getApplicationContext(), R.layout.custom_tab, null);
LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lp.setMargins(1, 0, 1, 0);
ImageView image = (ImageView) v.findViewById(R.id.tab_image);
TextView text = (TextView) v.findViewById(R.id.tab_text);
image.setImageDrawable(draw);
text.setText(name);
v.setLayoutParams(lp);
v.setBackgroundDrawable(res.getDrawable(R.drawable.tabindicator));
return v;
}
CustomTab.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_height="match_parent"
android:layout_width="match_parent">
<LinearLayout android:id="@+id/linearLayout1"
android:orientation="vertical"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_height="match_parent"
android:layout_width="match_parent">
<ImageView android:id="@+id/tab_image"
android:src="@drawable/icon"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:scaleType="centerInside"
android:layout_width="wrap_content">
</ImageView>
<TextView android:layout_gravity="center"
android:layout_height="wrap_content"
android:id="@+id/tab_text"
android:text="TextView"
android:layout_width="wrap_content"
android:layout_marginBottom="10px">
</TextView>
</LinearLayout>
TabHost.xml
<LinearLayout android:id="@+id/contain_nav"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@drawable/border_top">
<TabHost android:id="@+id/my_tabhost"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout android:weightSum="100"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="@+id/linearLayout1"
android:orientation="vertical">
<LinearLayout android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="@+id/linearLayout3">
<HorizontalScrollView android:layout_height="wrap_content"
android:id="@+id/horizontalScrollView2"
android:fillViewport="true"
android:layout_width="match_parent"
android:scrollbars="none">
<TabWidget android:orientation="horizontal"
android:id="@android:id/tabs"
android:layout_height="match_parent"
android:layout_width="wrap_content">
</TabWidget>
</HorizontalScrollView>
</LinearLayout>
<FrameLayout android:layout_height="0dp"
android:layout_width="match_parent"
android:id="@android:id/tabcontent">
<LinearLayout android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/tab1">
</LinearLayout>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="0dp"
android:id="@+id/tab2">
</LinearLayout>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tab3">
</LinearLayout>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tab4">
</LinearLayout>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tab5">
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
А вот как это должно выглядеть
(Mot XOOM)
Вот что я продолжаю получать
(Viewsonic Gtablet)
Я что-то упускаю, я знаю, плотность пикселей может повлиять на то, как все рендерится, но я просто не понимаю.