Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid - Issues with tabhost and aligning imageview and textview
    primarykey
    data
    text
    <p>Im trying to create a tab host as shown in the attached screen shot but having an issue with the icon image and alignment of text - the image needs to be aligned above the text but all attempts fail; </p> <p><a href="https://www.dropbox.com/sh/01p5v9mjy3l6t49/gtryTHS-fC" rel="nofollow">PM For Image if unable to see link here </a></p> <p>I've included some sample code but Im unable to force the image top align of the text - it only works if I increase the layout_height in the tab_indicator file to be greater than 66dip but Im restricted in space and the images supplied. If you cant see the image/link, the image is not forced above the text so it part of the image is behind the text!</p> <p>tab_indicator.xml</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="88.0dip" android:layout_height="66.0dip" android:layout_weight="1.0"&gt; &lt;include layout="@layout/tab_indicator_portrait" /&gt; &lt;/FrameLayout&gt; </code></pre> <p>tabindicator_protrait.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/tab_indicator_portrait" android:layout_width="fill_parent" android:layout_height="fill_parent" android:paddingBottom="3.0dip" android:paddingTop="3.0dip" &gt; &lt;ImageView android:id="@+id/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="top|center" android:layout_marginTop="3.0dip" /&gt; &lt;TextView android:id="@+id/title" style="?android:attr/tabWidgetStyle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|center" android:textColor="@color/tab_indicator_text" android:textSize="12.0dip" /&gt; &lt;/FrameLayout&gt; </code></pre> <p>tab_host.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;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" &gt; &lt;LinearLayout android:id="@+id/topLayout" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:padding="0.0dip" &gt; &lt;FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="0.0dip" android:layout_weight="1.0" /&gt; &lt;TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margin="0dip" android:padding="0dip" /&gt; &lt;/LinearLayout&gt; &lt;/TabHost&gt; </code></pre> <p>There are a few reasons why I've got it setup like this;</p> <ul> <li>the tab_indicator.xml file can also include a landscape file if i need to handle landscape differently i.e. further releases based on market feedback/testing</li> <li>allows the application to have a generic look and feel as I only want the icons to change when a user moves between tabs - had issues with tabhost in 4.0.4 and this seems like a cleaner way of handling it.</li> </ul> <p>I've tried some code in my TabActivity to handle the layout size based on screen size;</p> <pre><code>private void detectScreen() { Display localDisplay = getWindowManager().getDefaultDisplay(); if (localDisplay.getWidth() &lt; localDisplay.getHeight()) { int dips = 45; TabHost localTabHost = getTabHost(); DisplayMetrics localDisplayMetrics = getResources().getDisplayMetrics(); for (int i = 0; i &lt; localTabHost.getTabWidget().getTabCount(); i++) { View localView = localTabHost.getTabWidget().getChildTabViewAt(i); localView.getLayoutParams().height = ImageUtils.convertDIPToPixels(localDisplayMetrics, (float)dips); } } } </code></pre> <p>But again, changing the size of the layout DOES make the image smaller but not aligned with the text.</p> <p>The manifest file also contains the following;</p> <pre><code>&lt;supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:smallScreens="true"/&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload