Как убрать нежелательное перекрытие в андроиде

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

Вот мой код. Это табуляция, но таб-часть я вырезал. Если надо, добавлю.

ОБНОВЛЕНИЕ: забыл написать, что TextView у меня много, а не один

<FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="5dp" >

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">

            <ScrollView
                android:orientation="vertical"
                android:layout_height="fill_parent"
                android:layout_width="fill_parent">

                <LinearLayout
                    android:orientation="vertical"
                    android:layout_height="fill_parent"
                    android:layout_width="fill_parent">

                <TextView
                    android:text="welcome"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_alignParentTop="true" />

                <!-- A lot of TextView as the one above -->

                </LinearLayout>
            </ScrollView>

            <RelativeLayout
                android:id="@+id/InnerRelativeLayout"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true" >

                <Button
                     android:id="@+id/add"
                     android:layout_height="wrap_content"
                     android:layout_alignParentRight="true"
                     android:layout_width="fill_parent"
                     android:text="@string/add" />
            </RelativeLayout>
        </RelativeLayout>
    </FrameLayout>

И вот что он выдает. Как видите, внизу текст идет за кнопкой, но я хочу, чтобы они были в двух разных макетах.

Снимок экрана


person Andrea Carron    schedule 03.11.2011    source источник
comment
Откуда все приветствия?   -  person Kevin Galligan    schedule 03.11.2011
comment
Я обновил код. У меня много TextView, но я пишу в коде только один из них, чтобы он был короче   -  person Andrea Carron    schedule 04.11.2011


Ответы (2)


Попробуйте расположить его относительно над кнопкой.

<RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <ScrollView                
            android:orientation="vertical"
            android:layout_above="@+id/InnerRelativeLayout" //Add this
            android:layout_height="fill_parent"
            android:layout_width="fill_parent">

            <LinearLayout
                android:orientation="vertical"
                android:layout_height="fill_parent"
                android:layout_width="fill_parent">

            <TextView
                android:text="welcome"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true" />

            </LinearLayout>
        </ScrollView>

        <RelativeLayout
            android:id="@+id/InnerRelativeLayout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true" >

            <Button
                 android:id="@+id/add"
                 android:layout_height="wrap_content"
                 android:layout_alignParentRight="true"
                 android:layout_width="fill_parent"
                 android:text="@string/add" />
        </RelativeLayout>
    </RelativeLayout>
</FrameLayout>
person Peterdk    schedule 03.11.2011
comment
Пробую, но кнопка пропадает. - person Andrea Carron; 03.11.2011
comment
Хорошо, тогда попробуйте исправленную версию. - person Peterdk; 03.11.2011
comment
Вот почему вы не используете RelativeLayout. Высота fill_parent в ScrollView все испортит. Вы будете продолжать сталкиваться с этим, и в конечном итоге получите что-то, что работает. Или просто используйте LinearLayout и вес. - person Kevin Galligan; 04.11.2011

Не используйте RelativeLayout без крайней необходимости. Всегда. Я знаю, что это непопулярное мнение, но это то, что я всем говорю.

Я предполагаю, что вы хотите, чтобы прокрутка занимала как можно больше места, а кнопка была внизу?

<LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical">

            <ScrollView
                android:layout_height="wrap_content"
                android:layout_width="fill_parent"
                android:layout_weight="1">
                <LinearLayout
                android:layout_height="wrap_content"
                android:layout_width="fill_parent"
                android:orientation="vertical">
                <TextView
                    android:text="welcome"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"/>
                <TextView
                    android:text="welcome"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"/>
                <TextView
                    android:text="welcome"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"/>
                <TextView
                    android:text="welcome"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"/>
                <TextView
                    android:text="welcome"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"/>
                <TextView
                    android:text="welcome"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"/>
                <TextView
                    android:text="welcome"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"/>
                <TextView
                    android:text="welcome"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"/>
                <TextView
                    android:text="welcome"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"/>
                <TextView
                    android:text="welcome"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"/>
                <TextView
                    android:text="welcome"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"/>
                <TextView
                    android:text="welcome"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"/>
                <TextView
                    android:text="welcome"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"/>

                </LinearLayout>
            </ScrollView>

                <Button
                     android:id="@+id/add"
                     android:layout_height="wrap_content"
                     android:layout_width="fill_parent"
                     android:text="@string/add" />

        </LinearLayout>

Я думаю, что вы можете сбросить LinearLayout внутри ScrollView, предполагая, что у вас есть только 1 дочерний элемент (TextView)

person Kevin Galligan    schedule 03.11.2011
comment
Я забыл это написать, но, как вы можете видеть на изображении, у меня много виджетов (в примере TextView) внутри прокрутки. - person Andrea Carron; 03.11.2011
comment
ХОРОШО. Просто поместите LinearLayout в ScrollView - person Kevin Galligan; 04.11.2011
comment
Я изменил свой пример кода, чтобы включить его (я удалил его, но вернул обратно). В любом случае, это должно создать макет, который вы искали. - person Kevin Galligan; 04.11.2011