Подтвердить что ты не робот

Запретить просмотр перекрытий в RelativeLayout

Я пытаюсь разработать приложение для Android, но у меня возникают проблемы с дизайном графического интерфейса. Следующая часть снимка экрана - моя проблема (красные и синие линии были созданы с помощью параметров отладки Android).

my problem

Это код:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/caption"
    android:layout_below="@+id/caption" >

    <ImageButton
        android:id="@+id/button_edit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_alignParentRight="true"
        android:src="@drawable/content_edit"
        style="?android:attr/borderlessButtonStyle" />

    <TextView
        android:id="@+id/myText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:text="@string/num_placeholder"
        android:textAppearance="?android:attr/textAppearanceLarge" />


</RelativeLayout>

Как вы можете видеть, TextView myText перекрывает кнопку ImageButton button_edit. Простым решением было бы использовать LinearLayout вместо RelativeLayout. Проблема в том, что:

  • Мне нужна кнопка редактирования справа.
  • Мне нужен текст, чтобы заполнить остальную часть макета (очевидно, слева от кнопки редактирования)

Я также попытался установить myText layout_width на "fill_parent", но он заполнит весь остальной экран в левой части кнопки редактирования.

Ожидаемое поведение было бы myText, чтобы увеличить его высоту (став двустрочным TextView) вместо перекрытия 'button_edit'

Может ли кто-нибудь мне помочь? Благодаря

4b9b3361

Ответ 1

использовать layout_toLeftOf в макете TextView

вот так:

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/caption"
android:layout_below="@+id/caption" >

<ImageButton
    android:id="@+id/button_edit"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:layout_alignParentRight="true"
    android:src="@drawable/content_edit"
    style="?android:attr/borderlessButtonStyle" />

<TextView
    android:id="@+id/myText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_centerVertical="true"
    android:text="@string/num_placeholder"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:layout_toLeftOf="@+id/button_edit" />

Ответ 2

Другой способ - использовать атрибут android: layout_toEndOf

<ImageButton
    android:id="@+id/button_edit"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:layout_alignParentRight="true"
    android:src="@drawable/content_edit"
    style="?android:attr/borderlessButtonStyle"
    android:layout_toEndOf="@+id/myText" />

<TextView
    android:id="@+id/myText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_centerVertical="true"
    android:text="@string/num_placeholder"
    android:textAppearance="?android:attr/textAppearanceLarge" />