Android TabWidget不';在安卓2.1设备中看起来不太对劲
我的应用程序已将android:targetSdkVersion设置为11。它使用带有两个选项卡的Android TabWidget不';在安卓2.1设备中看起来不太对劲,android,android-layout,Android,Android Layout,我的应用程序已将android:targetSdkVersion设置为11。它使用带有两个选项卡的TabHost和TabWidget。但是,android:minSdkVersion设置为7(android 2.1) 我使用Android支持库(Android-Support-v13.jar)。我的选项卡在我能够测试的任何地方都看起来很好,除了在2.1中,它们似乎剪辑了构成选项卡内容的视图的一部分。这个问题在模拟器中也可以重现 以下是布局文件的相关部分: <?xml version="1.
TabHost
和TabWidget
。但是,android:minSdkVersion
设置为7(android 2.1)
我使用Android支持库(Android-Support-v13.jar
)。我的选项卡在我能够测试的任何地方都看起来很好,除了在2.1中,它们似乎剪辑了构成选项卡内容的视图的一部分。这个问题在模拟器中也可以重现
以下是布局文件的相关部分:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/repeat_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TabHost
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android: />
<FrameLayout>
...
</FrameLayout>
</TabHost>
</LinearLayout>
...
以下是我希望选项卡的外观:
以下是我在2.3设备中得到的信息:
基本上,选项卡似乎比需要的更高,并且与下面的FrameLayout
内容不必要地重叠
解决方案:
对于未来的访问者来说,如果您希望选项卡在2.1以下的所有平台上显示一致,唯一的解决方案是使用自定义选项卡视图。你会在这里找到一个非常好的方法。试试这个
<?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">
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" >
<TabWidget android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_weight="0" android:id="@android:id/tabs"
android:orientation="horizontal" />
<FrameLayout android:layout_width="fill_parent" android:layout_height="0dp"
android:layout_weight="1" android:id="@+android:id/realtabcontent" />
</LinearLayout>
</TabHost>
希望它能帮助。。。!!干杯…Android 2.3或2.1??API 7是2.1抱歉,它是2.1 API 7。感谢您的更正。对于
TabHost
tryandroid:layout\u width=“fill\u parent”
@mmohsnaeemandroid:layout\u width=“fill\u parent”
会处理选项卡的宽度。它们现在扩展到占据整个屏幕宽度。但是与下面的FrameLayout
的重叠仍然存在。请参见@RKN发布的答案。它会解决你的问题。我猜它很有魅力,但是有没有办法让TabWidget
与我的自定义背景一起显示,就像它们在第一张图片中一样?现在,在2.1中,它们显示为灰色和黑色(参见第二幅图)。