относительные проблемы макета / Android - PullRequest
0 голосов
/ 24 января 2012

У меня проблемы с созданием меню (не меню, когда вы нажимаете кнопку меню, а меню, как на экране приветствия для выбора пунктов).Я перешел на ImageView и TextView float (left / right) Android , и я не решил свою проблему.Я хотел бы создать по крайней мере пять или шесть вариантов для выбора в этом классе меню.Это мой файл menu.xml.Пожалуйста, дайте мне знать, что мне нужно сделать.

Проблема в том, что появляется первый элемент, но второй элемент перекрывает первый элемент.Я отказался от этого в течение последнего часа и не могу решить эту проблему.

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

спасибо вам.

Ответы [ 3 ]

2 голосов
/ 24 января 2012

Почему бы вам не использовать LinearLayout (например, вертикальный с несколькими маленькими горизонтальными внутри, каждый с TextView и ImageView)?

В любом случае, если вы хотитеиспользуйте RelativeLayout вы должны использовать что-то вроде android:layout_toRightOf, android:layout_toLeftOf, android:layout_above или android:layout_below в вашем XML для размещения ваших элементов.

Я советую вам взглянуть на http://developer.android.com/reference/android/widget/RelativeLayout.LayoutParams.html если вы не знаете эти параметры.

1 голос
/ 24 января 2012

Вы используете RelativeLayout, но не размещаете элементы со ссылкой друг на друга.

Пример:

<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

0 голосов
/ 24 января 2012

Линейный макет будет лучше.

Попробуйте и скажите мне, если это то, что вам нужно:

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