Question

enter image description here

Myself designing an app which uses GPS and Maps. I have created the UI as tabs. But i couldn't able to keep the font below the image.

Code in my 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 file in my drawable folder for tabs

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

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

Kindly help in aligning the font.

Was it helpful?

Solution

You need to provide

  • Small size of icons for small density devices in drawable-ldpi folder
  • Medium size of icons for medium density devices in drawable-mdpi folder
  • Large size icons for large density devices in drawable-hdpi folder

Here is documentation guide for sizes of the drawable and layouts.

if it doesn't solve your problem, you can consider provding your own customized tab indicator, which I've used in my post here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top