Android Tabhost tabs don';无法跨设备正确显示

Android Tabhost tabs don';无法跨设备正确显示,android,textview,android-3.0-honeycomb,android-tabhost,horizontalscrollview,Android,Textview,Android 3.0 Honeycomb,Android Tabhost,Horizontalscrollview,我在不同设备的tabhost中遇到了奇怪的行为。这让我觉得这个设备有问题(考虑到给我带来麻烦的是运行一个非官方的mod),但我想我还是会问 “我的选项卡”位于水平滚动视图中,目的是它们将扩展到分配的空间之外,但允许用户访问它们 这是我的密码 活动 // Set up Tabs TabHost tabs = (TabHost)findViewById(R.id.my_tabhost); tabs.setup(); TabSpec tspec1 = tabs.ne

我在不同设备的tabhost中遇到了奇怪的行为。这让我觉得这个设备有问题(考虑到给我带来麻烦的是运行一个非官方的mod),但我想我还是会问

“我的选项卡”位于水平滚动视图中,目的是它们将扩展到分配的空间之外,但允许用户访问它们

这是我的密码

活动

    // 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>
    <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>

TabHost.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>
    <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>

下面是它应该是什么样子 这是我一直得到的

我是否遗漏了一些我知道像素密度会影响渲染效果的东西,但我不明白这一点。

我也有同样的问题。 它与屏幕密度有关。在为
客户创建图像的同一层上创建标签背景图像。
我不喜欢为此设计图标和图像资源,但我已经将下面的链接提供给了一个喜欢图形的人,他做得很好


蜂巢3.0和horizantalscrollview实际上存在问题。这似乎是固定的3.1和更高。我使用的方法是删除布局中的滚动视图并将其放在layout-mdpi-v11文件夹中,然后将带有滚动视图的xml布局放在layout-mdpi-v12中


不是最好的解决办法,但截至撰写本文时,3.0只覆盖了0.2%的活动设备。

问题是。。。所有图标的设计都与您看到的几乎相同,因为某些原因,
scaletype=“centerInside
没有保留gTab上的内容。。。我甚至设置了images视图。我去测试了它,但文本仍然没有显示,只有当我将宽度设置为200dp时,它才起作用。您可以显示my_tabhost xml吗?因为isue可能位于该xml中,而不是customtab xml中,我想看看该xml中的
TabWidget
,确定它的位置。。。确实看到了一个不需要的
weightsum=100
(在工作scrollview中的不同尝试留下的)不幸的是,我让gtab在工作,所以明天才能测试。但是为什么XOOM和gtab之间存在差异呢