0

I would like to have a layout like below

Image TabName1 TabName2 TabName3 EditText

<-------------------- Tab Content ---------------------->

My xml below is not working. The image would show on top of tabs and the edittext is not even being shown at all...

<?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:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="5dp">

        <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/logo1" />

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" 
            android:showDividers="none" 
            android:background="#F0F0F0" />
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:padding="0dp" />

        <EditText
            android:layout_weight="1"
            android:id="@+id/qsearch"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:singleLine="true"
            android:lines="1"
            android:maxLines="1"
            android:scrollHorizontally="true"
            android:ellipsize="end"
            android:inputType="text"
            android:imeOptions="actionSearch|flagNoExtractUi" >
            <requestFocus />
        </EditText>     

    </LinearLayout>

</TabHost>
Eddi
  • 479
  • 5
  • 22

2 Answers2

1

try this..

you r setting framelayout height to fill parent so ur edittext is not visible.

if u want views in horizontal u just have to set android:orientation="horizontal".

if u r using weight property if ur orientation is vertical set height to 0dp, if ur orientation is horizontal set weight to 0dp and specify weight..

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

        <LinearLayout
            android:id="@+id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:padding="5dp" >

            <ImageView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:src="@drawable/ic_launcher" />

            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="#F0F0F0"
                android:showDividers="none" />

            <EditText
                android:id="@+id/qsearch"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:ellipsize="end"
                android:imeOptions="actionSearch|flagNoExtractUi"
                android:inputType="text"
                android:lines="1"
                android:maxLines="1"
                android:scrollHorizontally="true"
                android:singleLine="true"
                android:text="sdfsf" >

                <requestFocus />
            </EditText>
        </LinearLayout>

        <RelativeLayout
            android:id="@+id/content"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
             >

            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:padding="0dp" />

        </RelativeLayout>
    </LinearLayout>

</TabHost>
M S Gadag
  • 2,057
  • 1
  • 12
  • 15
1

setting the android:weightSum to the parent layout and dividing child layouts is a good habit and you can also divide the layout as you want just by changing the values for android:layout_weight property in child layouts

i have just divided layouts you can change the values of the weight accordingly

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

        <LinearLayout
            android:id="@+id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:padding="5dp"
            android:weightSum="5" >

            <ImageView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:src="@drawable/ic_launcher" />

            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="2"
                android:background="#F0F0F0"
                android:showDividers="none" />

            <EditText
                android:id="@+id/qsearch"
                android:layout_width="0dp"
                android:layout_height="fill_parent"
                android:layout_weight="2"
                android:ellipsize="end"
                android:imeOptions="actionSearch|flagNoExtractUi"
                android:inputType="text"
                android:lines="1"
                android:maxLines="1"
                android:scrollHorizontally="true"
                android:singleLine="true"
                android:text="sdfsf" >

                <requestFocus />
            </EditText>
        </LinearLayout>

        <RelativeLayout
            android:id="@+id/content"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
             >

            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:padding="0dp" />

        </RelativeLayout>
    </LinearLayout>

</TabHost>

hope this helps.

karan
  • 8,637
  • 3
  • 41
  • 78