1

在此处输入图像描述

我自己设计了一个使用 GPS 和地图的应用程序。我已将 UI 创建为选项卡。但我无法将字体保留在图像下方。

我的 Mainactivity 中的代码

TabSpec gpsspec = tabHost.newTabSpec("GPS");
gpsspec.setIndicator("GPS", getResources().getDrawable(R.drawable.gps));
Intent gpsIntent = new Intent(this, GpsActivity.class);
gpsspec.setContent(gpsIntent);
tabHost.addTab(gpsspec);

我的可绘制文件夹中用于选项卡的 XML 文件

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- When selected, use grey -->
    <item android:drawable="@drawable/gps_icon"
          android:state_selected="true" />
    <!-- When not selected, use white-->
    <item android:drawable="@drawable/gps_icon" />
</selector>

主.xml

<?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:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />
    </LinearLayout>

</TabHost>

请帮助对齐字体。

4

1 回答 1

3

您需要提供

  • drawable-ldpi文件夹中小密度设备的小图标
  • drawable-mdpi文件夹中中等密度设备的中等大小图标
  • drawable-hdpi文件夹中大密度设备的大尺寸图标

是有关可绘制和布局大小的文档指南。

如果它不能解决您的问题,您可以考虑提供您自己的自定义选项卡指示器,我在此处的帖子中使用了该指示器。

于 2012-03-08T08:56:38.603 回答