MCarter
MCarter

Reputation: 53

relative layout issues/android

I am having issues with creating a menu (not menu when you click menu button -- but menu as in the welcome screen to select items). I went to ImageView and TextView float (left/right) Android and I did not solve my issue. I would like to create at least five or six options to select from on this menu class. This is my menu.xml file. Please let me know what I need to do.

The issue is that the first item appears, but the second item overlaps the first item. I been picking away with this for the last hour and cannot solve this issue.

<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:padding="5dp">
<TextView
    android:textSize="18dp"
    android:id="@+id/message_view"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="   Check Your Account" />

<ImageView
    android:src="@drawable/ic_menu_add"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/icon" />

    <TextView
    android:textSize="18dp"
    android:id="@+id/message_view"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="   View our Site" />

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

</RelativeLayout>

thannk you.

Upvotes: 0

Views: 1418

Answers (3)

Xavi Gil
Xavi Gil

Reputation: 11568

A Linear Layout would be better.

Try this and tell me if this is what you needed:

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

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >
        <TextView
            android:id="@+id/message_view"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="   Check Your Account"
            android:textSize="18dp" />
        <ImageView
            android:id="@+id/icon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_menu_add" android:layout_gravity="center_horizontal"/>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <TextView
            android:id="@+id/message_view"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="   View our Site"
            android:textSize="18dp" />
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_menu_add" android:layout_gravity="center_horizontal"/>
    </LinearLayout>

</LinearLayout>

Upvotes: 0

Jeremy D
Jeremy D

Reputation: 4855

You use a RelativeLayout but you don't place elements with reference to each other.

Example :

<RelativeLayout   
   xmlns:android="http://schemas.android.com/apk/res/android"   
   android:orientation="vertical"   
   android:layout_width="fill_parent"   
   android:layout_height="fill_parent"  
   >   
   <Button android:id="@+id/topBtn"   
     android:layout_width="wrap_content"   
     android:layout_height="wrap_content"   
     android:text="Top"   
     android:layout_centerHorizontal="true">  
  </Button>  

  <Button android:id="@+id/leftBtn"   
    android:layout_width="wrap_content"   
    android:layout_height="wrap_content"   
    android:text="Left"  
    android:layout_below="@+id/topBtn"  
    android:layout_toLeftOf="@+id/topBtn">  
  </Button> 
</RelativeLayout>

http://developer.android.com/reference/android/widget/RelativeLayout.html

Upvotes: 1

Zoleas
Zoleas

Reputation: 4879

Why don't you use a LinearLayout (like a vertical one with severals little horizontal ones inside, each with a TextView and an ImageView) ?

Anyway, if you want to use RelativeLayout you should use something like android:layout_toRightOf, android:layout_toLeftOf, android:layout_above or android:layout_below in your xml to place your elements.

I advise you to take a look at http://developer.android.com/reference/android/widget/RelativeLayout.LayoutParams.html if you don't know those parameters.

Upvotes: 2

Related Questions