向android布局添加滚动视图

向android布局添加滚动视图,android,android-scrollview,Android,Android Scrollview,我有一个相对布局,我想在其中添加一个滚动视图,问题是当我添加滚动视图时,我的所有相对设置的小部件都失去了位置,我尝试了每一种可能性,但我无法正确设置滚动视图,有人能帮我吗?我想将滚动视图放在xml文件的所有元素上 新代码: <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:l

我有一个相对布局,我想在其中添加一个滚动视图,问题是当我添加滚动视图时,我的所有相对设置的小部件都失去了位置,我尝试了每一种可能性,但我无法正确设置滚动视图,有人能帮我吗?我想将滚动视图放在xml文件的所有元素上

新代码:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff" >

    <ImageButton
        android:id="@+id/linearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="140dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_weight="0.9"
        android:background="@drawable/subscribe_second_top"
        android:orientation="vertical" >
    </ImageButton>





            <EditText
                android:id="@+id/editText1"
                android:layout_width="270dp"
                android:layout_height="wrap_content"
                android:layout_below="@+id/bebasNeueTextView1"
                android:layout_centerHorizontal="true"
                android:ems="10"
                android:inputType="textEmailAddress" />

            <TextView
                android:id="@+id/bebasNeueTextView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/editText1"
                android:layout_centerHorizontal="true"
                android:text="THE EMAIL YOU WILL USE TO GET ALL YOUR APPS CREATED BY THE SOFT"
                android:textColor="#000000"
                android:textSize="7sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/bebasNeueTextView6"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/editText2"
                android:layout_centerHorizontal="true"
                android:text="YOUR GOOGLE PLAY STORE ORDER NUMBER, IN ORDER TO PROVE YOU BOUG"
                android:textColor="#000000"
                android:textSize="7sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/bebasNeueTextView4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/bebasNeueTextView2"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="16dp"
                android:text="ENTER YOUR PLAY STORE ORDER NUMBER"
                android:textColor="#94c23e"
                android:textSize="13sp"
                android:textStyle="bold" />

            <RelativeLayout
                android:layout_width="fill_parent"
                android:layout_height="80dp"
                android:layout_alignParentBottom="true"
                android:background="@drawable/subscribe_second_bottom"
                android:paddingBottom="5dp"
                android:paddingTop="30dp" >

                <com.apkcreator.fwd.BebasNeueButton
                    android:id="@+id/finishButton"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentBottom="true"
                    android:layout_centerHorizontal="true"
                    android:background="#94c23e"
                    android:paddingBottom="10dp"
                    android:paddingLeft="30dp"
                    android:paddingRight="30dp"
                    android:paddingTop="10dp"
                    android:text="FINISH"
                    android:textSize="18sp"
                    android:textStyle="bold" />
            </RelativeLayout>

            <TextView
                android:id="@+id/bebasNeueTextView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="170dp"
                android:text="ENTER YOUR EMAIL"
                android:textColor="#94c23e"
                android:textSize="13sp"
                android:textStyle="bold" />

            <EditText
                android:id="@+id/editText2"
                android:layout_width="270dp"
                android:layout_height="wrap_content"
                android:layout_alignLeft="@+id/editText1"
                android:layout_below="@+id/bebasNeueTextView4"
                android:ems="10" 
                android:layout_centerHorizontal="true">


            </EditText>

</RelativeLayout>
 </ScrollView>


请查看下面的代码,这可能会有所帮助。根据需要重新排列项目,在使用任何项目的任何属性之前,请先阅读该属性

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="#ffffff" >

    <ImageButton
        android:id="@+id/linearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="140dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="5dp"
        android:layout_weight="0.9"
        android:background="@drawable/ic_launcher"
        android:orientation="vertical" >
    </ImageButton>

    <EditText
        android:id="@+id/editText1"
        android:layout_width="270dp"
        android:layout_height="wrap_content"
        android:layout_below="@+id/linearLayout1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="5dp"
        android:ems="10"
        android:inputType="textEmailAddress" />

    <TextView
        android:id="@+id/bebasNeueTextView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/editText1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="5dp"
        android:text="THE EMAIL YOU WILL USE TO GET ALL YOUR APPS CREATED BY THE SOFT"
        android:textColor="#000000"
        android:textSize="7sp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/bebasNeueTextView6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/bebasNeueTextView2"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="5dp"
        android:text="YOUR GOOGLE PLAY STORE ORDER NUMBER, IN ORDER TO PROVE YOU BOUG"
        android:textColor="#000000"
        android:textSize="7sp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/bebasNeueTextView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/bebasNeueTextView6"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="5dp"
        android:text="ENTER YOUR PLAY STORE ORDER NUMBER"
        android:textColor="#94c23e"
        android:textSize="13sp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/bebasNeueTextView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/bebasNeueTextView4"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="5dp"
        android:text="ENTER YOUR EMAIL"
        android:textColor="#94c23e"
        android:textSize="13sp"
        android:textStyle="bold" />

    <EditText
        android:id="@+id/editText2"
        android:layout_width="270dp"
        android:layout_height="wrap_content"
        android:layout_below="@+id/bebasNeueTextView1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="5dp"
        android:ems="10" >
    </EditText>

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="80dp"
        android:layout_alignParentBottom="true"
        android:layout_below="@+id/editText2"
        android:layout_marginTop="5dp"
        android:paddingBottom="5dp" >

        <com.apkcreator.fwd.BebasNeueButton
            android:id="@+id/finishButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:background="#94c23e"
            android:paddingBottom="10dp"
            android:paddingLeft="30dp"
            android:paddingRight="30dp"
            android:paddingTop="10dp"
            android:text="FINISH"
            android:textSize="18sp"
            android:textStyle="bold" />
    </RelativeLayout>
</RelativeLayout>

</ScrollView>

这是因为将RelativeLayout的高度设置为与ScrollView中的父项匹配没有任何意义。尝试使用ScrolView的fillViewport属性。将此行添加到ScrollView元素:

android:fillViewport="true"

我自己还没试过。也许它会对你有所帮助。有关更多信息,请查看官方和官方网站

只需将xml代码的开头更改为:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent" 
     android:fillViewport="true">

     <RelativeLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:background="#ffffff" >

检查此链接:

您的问题可能与视口有关,ScrollLayout上的android:fillViewport=“true”应该可以解决您的问题

查看xml时,可以使用垂直线性布局来设置此文件,对于本用例来说更简单

顺便说一句,我的建议是避免用户输入上的滚动条,如注册、登录。。。您的表单只包含2个字段,我相信您可以将其安排为一次全部显示在屏幕上(更好的用户体验!)

使用

androd:margintTop="+5dp\-5dp"

根据需要在所有面上显示+或-值

您想在哪里插入滚动视图?将滚动视图放在realtive layout的上方,然后粘贴xml代码。只需将滚动视图放在父布局中没有用,我已将滚动视图放在父布局中,但仍然不起作用我现在编辑了代码,我已将滚动视图添加到其中,问题是,我的相对布局(就在滚动视图之后)没有得到任何填充父视图的高度。没有使用,我编辑了代码,并查看了我如何尝试放置滚动视图,我的相对布局的高度没有设置为填充父视图。您是否使用滚动视图作为根组件?在我完全相同的情况下,我总是把LinearLayout作为根,一个ScrolView(高度包裹内容)和一个RelativeLayout(高度包裹内容)。我不确定这对你的情况是否有帮助,FYR……让我尝试一些不同的方法,顺便说一句,谢谢你的帮助。请记住我的问题很有用,因为这会帮助很多人
androd:margintTop="+5dp\-5dp"