anusha
anusha

Reputation: 55

Nested linear layout in frame layout is not working

This is my code!! here i have added background image and i need the buttons,labels and textfields to get displayed above the background image.I have used frame layout but iam not getting the expected result! Only the background image is filling the screen but the buttons and other stufs are not getting displayed!! Iam new to android..Plz help !!!

   <FrameLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

   <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:paddingRight="40dp" >

        <TextView
            android:id="@+id/tvname1"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="left"
            android:text="your  name"
            android:textSize="20dp"
            android:textStyle="italic" />

        <EditText
            android:id="@+id/etboyname"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="boyname" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/tvname2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="your crushs name"
            android:textSize="20dp"
            android:textStyle="italic" >
        </TextView>

        <EditText
            android:id="@+id/etgirlname"
            android:layout_width="130dp"
            android:layout_height="wrap_content"
            android:hint="girlname" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/btclick"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_margin="15dp"
            android:layout_marginLeft="15dp"
            android:layout_weight="1"
            android:background="@drawable/custom" />

        <Button
            android:id="@+id/btsamegender"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginLeft="15dp"
            android:layout_weight="1"
            android:background="@drawable/gender2" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/tvsame1"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="left"
            android:layout_marginLeft="15dp"
            android:text="opposite gender"
            android:textSize="20dp"
            android:textStyle="italic" />

        <TextView
            android:id="@+id/tvsame1"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="left"
            android:layout_marginLeft="15dp"
            android:text="same gender"
            android:textSize="20dp"
            android:textStyle="italic" />
    </LinearLayout>

      </LinearLayout>

    <ImageView
      android:id="@+id/imageanim"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
       />
     </FrameLayout>

Upvotes: 2

Views: 6100

Answers (1)

Dyrborg
Dyrborg

Reputation: 877

Your imageview takes up the entire screen because it is set to "fill_parent". It more or less lays on top of all your other layouts, because you are adding it as the last view, which is why you do not see them when running your app.

Try and move your imageview above your top level linear layout and see if that doesn't fix your problem.

However in general - to add a background do as suggested in the answer to this question: how to add background image to activity?

EDIT:

This is what I am suggesting - your XML file should begin like this.

<FrameLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >

    <ImageView
     android:id="@+id/imageanim"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     />

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:paddingRight="40dp" >

Upvotes: 4

Related Questions