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

Круговые зависимости не могут существовать в RelativeLayout, Android?

У меня есть следующий макет: Мне нужно держать кнопку внизу экрана, и она должна быть видимой пользователю. Остальная часть макета должна прокручиваться.

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.vfc.sargroup.SalesOrderActivity$PlaceholderFragment" >

<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/bottomLinearLayout" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Select Distributor Name"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <Spinner
            android:id="@+id/spinner1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Payment Collection"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10" >
        </EditText>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Product Category"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10" >

            <requestFocus />
        </EditText>

        <TableLayout
            android:id="@+id/salesTableLayout"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:stretchColumns="*" >
        </TableLayout>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Total QTY"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10" >

            <requestFocus />
        </EditText>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Total Price"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10" >

            <requestFocus />
        </EditText>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Remark"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10" >
        </EditText>
    </LinearLayout>
</ScrollView>

<LinearLayout
    android:id="@+id/bottomLinearLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_below="@+id/scrollView1"
    android:layout_centerHorizontal="true"
    android:orientation="vertical" >

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

Мне просто нужно прокрутить мой просмотр и оставить кнопку на экране внизу.

Проблема заключается в

     android:layout_above="@+id/bottomLinearLayout"

Я получаю сообщение об ошибке

     Circular dependencies cannot exist in RelativeLayout

Что не так с моим расположением?

4b9b3361

Ответ 1

Проблема вызвана тем, что в параметрах макета имеется круговая ссылка.

Например, когда view B является layout_below view A, view A больше не может ссылаться на вид B ниже, alignRight и т.д. Это также может существовать между несколькими видами: ссылки B ссылок C. В этом сценарии C может ' t reference A из-за круговой зависимости.

Вы использовали: -

bottomLinearLayout находится ниже scrollView1 И тогда вы сказали, что scrollView1 находится выше bottomLinearLayout

Это не работает. Используйте один

Ответ 2

Вы не можете сказать, что bottomLinearLayout находится ниже scrollView1, а затем скажем, что scrollView1 находится выше bottomLinearLayout. Сделайте только один, не оба.

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

Ответ 3

Добавьте android:layout_alignParentTop="true" в свой scrollView и удалите android:layout_below="@+id/scrollView1" в bottomLinearLayout.

Ответ 4

Закройте свой вид прокрутки в Relative Layout.

Структура будет:

<RelativeLayout
......
....
.....>

<RelativeLayout
.....
.....
.....>

<ScrollView
....
...
...>

put your staff here

</ScrollView>
</RelativeLayout>


<RelativeLayout
....
....
below the above relative layout
...../>

<Button
....
....
..../>

</RelativeLayout>

</RelativeLayout>