Выравнивание текстовых представлений

1

Я разрабатываю приложение для Android, относительный макет которого приведен ниже.

Вот ссылка imgur на то, как приложение отображается на экране: http://imgur.com/c4rNJ. Я бы хотел, чтобы "Текст 1" появился прямо над "ленивой лисой". Надеюсь, что поможет прояснить то, что я хочу выполнить.

    <?xml version="1.0" encoding="utf-8"?>

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="wrap_content" android:layout_width="fill_parent"
    android:background="@color/white">

    <TextView android:id="@+id/text1" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:layout_marginLeft="0dip"


        android:textColor="@color/black" android:text="Text 1" android:lines="1"
        android:scrollHorizontally="true" android:ellipsize="end" />

    <Button android:id="@+id/checkBox" android:layout_height="wrap_content"
        android:layout_width="wrap_content" android:drawableRight="@drawable/checkbox_unchecked_30"
        android:layout_below="@+id/text1" android:background="@color/white" />

    <TextView android:id="@+id/text2" android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:layout_toRightOf="@+id/checkBox"
        android:layout_alignTop="@+id/checkBox" android:layout_below="@+id/text1"


        android:textColor="@color/black" android:text="a lazy fox jumped over the dam and said help"

        android:lines="1" android:scrollHorizontally="true" android:ellipsize="end" />

    <TextView android:id="@+id/text3" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:layout_toRightOf="@+id/checkBox"
        android:layout_below="@+id/text2" android:textColor="@color/black"
        android:text="Text 3" />

    <TextView android:id="@+id/text4" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:layout_below="@+id/text2"
        android:layout_toRightOf="@+id/text3" android:textColor="@color/black"
        android:text="Text 4" />

    <TextView android:id="@+id/text5" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:layout_below="@+id/text2"
        android:layout_toRightOf="@+id/text4" android:textColor="@color/black"
        android:text="Text 5" />

</RelativeLayout>

Я хочу, чтобы "Текст 1" появлялся прямо над текстом, начинающимся с "ленивой лисы...". Прямо сейчас над флажком появляется "Текст 1" . Я не уверен, как достичь вышеуказанного. Я пробовал разные вещи, но ничего не работает. Что я должен делать для достижения желаемого макета?

  • 0
    Пожалуйста, предоставьте изображение того, чего вы пытаетесь достичь.
  • 0
    @ Макарсе я не могу, так как респ слишком низкий.
Показать ещё 1 комментарий
Теги:
layout

4 ответа

2
Лучший ответ

Я нацелился на Android 1.5, в котором прямые ссылки не работают в RelativeLayout. Прямые ссылки были впервые реализованы в Android 1.6 (см. http://developer.android.com/resources/articles/ui-1.6.html), и поэтому любое из предлагаемых решений другими не работало.

3

Вам нужно добавить атрибут layout_alightLeft к вашему text1:

<TextView android:id="@+id/text1" 
    android:layout_alignLeft="@+id/text2"
    ...
/>

Изображение 174551


Полный файл макета:

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

    <TextView android:id="@+id/text1" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:layout_marginLeft="0dip"
        android:layout_alignLeft="@+id/text2"
        android:text="Text 1"
        android:lines="1"
        android:scrollHorizontally="true" 
        android:ellipsize="end" />

    <Button
        android:id="@+id/checkBox" 
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"        
        android:layout_below="@+id/text1"
        android:text="button"  />

    <TextView 
        android:id="@+id/text2" 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:layout_toRightOf="@+id/checkBox"
        android:layout_alignTop="@+id/checkBox" 
        android:layout_below="@+id/text1"         
        android:text="a lazy fox jumped over the dam and said help"
        android:lines="1" 
        android:scrollHorizontally="true"
         android:ellipsize="end" />

    <TextView 
        android:id="@+id/text3" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:layout_toRightOf="@+id/checkBox"
        android:layout_below="@+id/text2"        
        android:text="Text 3" />

    <TextView 
        android:id="@+id/text4" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:layout_below="@+id/text2"
        android:layout_toRightOf="@+id/text3"        
        android:text="Text 4" />

    <TextView
        android:id="@+id/text5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/text2"
        android:layout_toRightOf="@+id/text4"        
        android:text="Text 5" />

</RelativeLayout>
  • 0
    хм, это изменение не работает для меня.
  • 0
    Я обновил ответ с полной копией моего файла макета. Попробуй.
Показать ещё 8 комментариев
1

Если я правильно понимаю ваше требование, вы хотите, чтобы "Text1" отображался прямо вверху/выровнен с "ленивой лисой...".

Попробуйте изменить определение первого TextView на это (обратите внимание на последний атрибут):

    <TextView
    android:id="@+id/text1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="0dip"
    android:textColor="@color/black"
    android:text="Text 1"
    android:lines="1"
    android:scrollHorizontally="true"
    android:ellipsize="end"
    android:layout_alignLeft="@+id/text2" />

EDIT: Здесь полный файл макета:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:background="@android:color/white">

<TextView
    android:id="@+id/text1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="0dip"
    android:textColor="@android:color/black"
    android:text="Text 1"
    android:lines="1"
    android:scrollHorizontally="true"
    android:ellipsize="end"
    android:layout_alignLeft="@+id/text2" />

<Button
    android:id="@+id/checkBox"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:layout_below="@+id/text1"
    android:drawableRight="@drawable/checkbox_unchecked_30"
    android:background="@android:color/white" />

<TextView
    android:id="@+id/text2"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@+id/checkBox"
    android:layout_alignTop="@+id/checkBox"
    android:layout_below="@+id/text1"


    android:textColor="@android:color/black"
    android:text="a lazy fox jumped over the dam and said help"

    android:lines="1"
    android:scrollHorizontally="true"
    android:ellipsize="end" />

<TextView
    android:id="@+id/text3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@+id/checkBox"
    android:layout_below="@+id/text2"
    android:textColor="@android:color/black"
    android:text="Text 3" />

<TextView
    android:id="@+id/text4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/text2"
    android:layout_toRightOf="@+id/text3"
    android:textColor="@android:color/black"
    android:text="Text 4" />

<TextView
    android:id="@+id/text5"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/text2"
    android:layout_toRightOf="@+id/text4"
    android:textColor="@android:color/black"
    android:text="Text 5" />
</RelativeLayout>
  • 0
    Кажется, не работает. Я уже попробовал это.
  • 0
    Я попробовал это, и это работает на моем телефоне. Хммм ...
Показать ещё 5 комментариев
0

Я думаю, вы должны добавить android: layout_below="@id/editText2" в text1

Ещё вопросы

Сообщество Overcoder
Наверх
Меню