Я разрабатываю приложение для 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" . Я не уверен, как достичь вышеуказанного. Я пробовал разные вещи, но ничего не работает. Что я должен делать для достижения желаемого макета?
Я нацелился на Android 1.5, в котором прямые ссылки не работают в RelativeLayout. Прямые ссылки были впервые реализованы в Android 1.6 (см. http://developer.android.com/resources/articles/ui-1.6.html), и поэтому любое из предлагаемых решений другими не работало.
Вам нужно добавить атрибут layout_alightLeft
к вашему text1
:
<TextView android:id="@+id/text1"
android:layout_alignLeft="@+id/text2"
...
/>
Полный файл макета:
<?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>
Если я правильно понимаю ваше требование, вы хотите, чтобы "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>
Я думаю, вы должны добавить android: layout_below="@id/editText2"
в text1