本文介绍了android 相对布局中不能存在循环依赖?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下布局:我需要将按钮保持在屏幕底部,并且它应该对用户可见.布局的其余部分应该滚动.

I have the following layout:I need to keep the button at the bottom of screen and it should be visible to the user.The rest of the layout should scroll.

    <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>

我只需要滚动视图并保持按钮出现在屏幕底部.

I just need to do scroll my view and keep the button appeared on the screen at the bottom.

问题出在

     android:layout_above="@+id/bottomLinearLayout"

我收到错误

     Circular dependencies cannot exist in RelativeLayout

我的布局有什么问题?

推荐答案

问题是因为布局参数中存在循环引用.

The problem is caused because there is a circular reference in the layout parameters.

例如,当视图 B 是 layout_below 视图 A 时,视图 A 不能再引用它下面的视图 B,alignRight 等.这也可以存在于多个视图之间:A 引用 B 引用 C.在这种情况下,C 可以'由于循环依赖,t 引用 A.

For example, when view B is layout_below view A, view A can't reference view B anymore in it's below, alignRight etc. This can also exist between multiple views: A references B references C. In that scenario C can't reference A because of a circular dependency.

你用过:-

bottomLinearLayout 低于 scrollView1然后你说 scrollView1 在 bottomLinearLayout 之上

bottomLinearLayout is below scrollView1And then you said that scrollView1 is above bottomLinearLayout

它不是那样工作的.使用一个

It dosen't work like that.Use one

这篇关于android 相对布局中不能存在循环依赖?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 09:45