简体   繁体   English

将滚动视图添加到android布局

[英]Adding a Scroll View to the android layout

I have a relative layout in which i want to add a scrollView, the problem is when ever i add the scroll view, all of my relatively set widgets lost their places, i have tried each and every possibility but i am unable to set the scroll view properly, can anybody help me in that? 我有一个相对布局我要添加一个scrollView,问题是当我添加滚动视图时,我所有相对设置的小部件都丢失了他们的位置,我已经尝试了每一种可能性但我无法设置滚动正确看待,有人可以帮助我吗? I want to put the scroll view to all of my elements of the xml file. 我想将滚动视图放到xml文件的所有元素中。

NEW CODE: 新代码:

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

Check this link: How to add scroll bar to the Relative Layout? 检查此链接: 如何将滚动条添加到相对布局?

Your problem may be related with the viewport, android:fillViewport="true" on the ScrollLayout should solve your problem. 您的问题可能与视口有关, android:fillViewport="true"上的android:fillViewport="true"应该可以解决您的问题。

Viewing your xml, You can set this file using a vertical LinearLayout, much more simple for this use case. 查看xml,您可以使用垂直LinearLayout设置此文件,对于此用例更加简单。

BTW, my advise is to avoid scrollbars on user inputs like registration, login... Your form only contains 2 fields, I'm sure you can arrange it to be all shown on screen at once (much better UX!). 顺便说一句,我的建议是避免用户输入上的滚动条,如注册,登录...你的表单只包含2个字段,我相信你可以安排它一次全部显示在屏幕上(更好的用户体验!)。

Just change the beginning of your xml code to: 只需将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" >

That's because setting height of RelativeLayout to match_parent inside ScrollView doesn't make any sense. 那是因为在ScrollView中将RelativeLayout的高度设置为match_parent没有任何意义。 Try using fillViewport property of ScrolView. 尝试使用ScrolView的fillViewport属性。 Add this line to your ScrollView element : 将此行添加到ScrollView元素:

android:fillViewport="true"

I haven't tried it myself.Maybe it will help you.For more info look at official documentation and here . 我自己没有尝试过。也许它会帮助你。有关更多信息,请查看官方文档此处

<LinearLayout>
  <ScrollView>
    <RelativeLayout>
      <put your all UI component here />
    </RelativeLayout>
  </ScrollView>
</LinearLayout>

set elements using 使用设置元素

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

means + or - value on all side as required 根据需要在所有方面表示+或 - 值

Please look at the code below, this might help. 请查看下面的代码,这可能会有所帮助。 Rearrange the items as you want and before using any property of any item please give it a read. 根据需要重新排列项目,在使用任何项目的任何属性之前,请阅读。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM