Mahe
Mahe

Reputation: 2737

android Layouts overlapping ListView and LinearLayout

I am using FrameLayout in which I am having a search Textbox and Button and a ListView to be displayed in the next line of the TextBox

My layout is like this ,

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<ImageView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:scaleType="fitXY"
    android:src="@drawable/pattern1" />

<LinearLayout
    android:id="@+id/LinearLayout02"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_gravity="top" >

    <Button
        android:id="@+id/btnadd"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:onClick="addCustomers"
        android:text="Add"
        android:textColor="#000000" >
    </Button>

    <EditText
        android:id="@+id/edtSearch"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="2"
        android:ems="10"
        android:hint="Search"
        android:inputType="textPersonName" >

        <requestFocus />
    </EditText>

</LinearLayout>

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_marginTop="60dp"
    android:gravity="bottom" 
    android:orientation="vertical">

    <ListView
        android:id="@+id/list_customers"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="bottom|center_horizontal" >

    </ListView>

</LinearLayout>

</FrameLayout>

I am using this TextView to diplay List item in the ListView,

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/txtsimple_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"
android:gravity="center_vertical"    
android:textSize="20sp"
android:textStyle="bold" />

I have given margin top attribute for the ListView, but even though it overlaps on the Button and EditText controls.

I am using a FrameLayout but of no use. Please suggest me any help!! Any help is appreciated!!

Upvotes: 2

Views: 5058

Answers (5)

jack
jack

Reputation: 11

FrameLayout is not the best option. You can use other layouts, eg, GridLayout, RelativeLayout or ListView.

Upvotes: 1

Singh Arjun
Singh Arjun

Reputation: 2464

FrameLayout are used very less,beacuse they are used to display single view or views which overlaps each other.

So you should use RelativeLayout.

Upvotes: 1

Neoh
Neoh

Reputation: 16164

You should use LinearLayout as parent, just set android:orientation="vertical".

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:scaleType="fitXY"
        android:src="@drawable/pattern1" />
    <LinearLayout
        android:id="@+id/LinearLayout02"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_gravity="top" >
        ...

    </LinearLayout>
    <ListView
    android:id="@+id/list_customers"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="bottom|center_horizontal" >
    ...
    </ListView>

</LinearLayout>

Upvotes: 4

Onur A.
Onur A.

Reputation: 3017

+1 Neoh and remove imageview, instead put the image as background image attribute at parent view

android:background="@drawable/pattern1"

Upvotes: 1

Stefan de Bruijn
Stefan de Bruijn

Reputation: 6319

FrameLayout has no 'rules of placement' so everything just stacks on to each other.

Instead, use a LinearLayout with android:orientation="vertical"
or use a RelativeLayout and add positioning values to the childs, such as android:layout_below

Upvotes: 3

Related Questions