Проблема проектирования RelativeLayout: ScrollView между RelativeLayout и Button - PullRequest
3 голосов
/ 08 ноября 2011

Макет моей деятельности должен быть следующим:

  • Экран разделен на 3 секции (3 «строки»)
  • Первый раздел состоит из изображения слева,и два TextViews рядом с ним.
  • второй раздел - это большой текст, помещенный в ScrollView, чтобы его можно было прокручивать.
  • третий раздел - просто кнопка, и эта кнопка должна находиться навсегда внизу экрана.

Итак, и 1-я, и 3-я секции должны быть зафиксированы, прокручивать можно только 2-ю секцию.

Вот мой код:

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

<RelativeLayout
    android:id="@+id/relativeLayout1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"            
        android:layout_toRightOf="@id/imageView1"
        android:text="TextView" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"            
        android:layout_toRightOf="@id/imageView1"
        android:layout_below="@id/textView1"
        android:text="TextView" />

</RelativeLayout>

<RelativeLayout 
    android:id="@+id/relativeLayout2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/relativeLayout1">      

    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >    

        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text " />

    </ScrollView>

</RelativeLayout>

<RelativeLayout 
    android:id="@+id/relativeLayout3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@id/relativeLayout2">

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />

</RelativeLayout>

</RelativeLayout>

Проблема здесь довольно очевидна:

enter image description here

Текст в средней части можно хорошо прокручивать, но проблема в том, что ScrollView не«конец», когда кнопка «начинается» в макете.

Ответы [ 2 ]

2 голосов
/ 08 ноября 2011

Попробуйте это:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <RelativeLayout
        android:id="@+id/relativeLayout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:src="@drawable/ic_launcher" />

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/imageView1"
            android:text="TextView" />

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/textView1"
            android:layout_toRightOf="@id/imageView1"
            android:text="TextView" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/relativeLayout2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:layout_below="@id/relativeLayout1" >

        <ScrollView
            android:id="@+id/scrollView1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/textView3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text " />
        </ScrollView>
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/relativeLayout3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@id/relativeLayout2" >

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />
    </RelativeLayout>

</LinearLayout>
1 голос
/ 10 сентября 2013

Я просто хотел бы добавить, что вы можете решить эту проблему, используя RelativeLayout в качестве внешнего макета (вместо LinearLayout, как в примере Luksprogs). Допустим, у вас есть два представления: viewAbove и viewBelow, и вы хотите заполнить пространство между двумя представлениями другим представлением. Добавьте это к последнему виду:

android:layout_below="@id/viewAbove"
android:layout_above="@id/viewBelow"
...