我正在尝试创建一个应该包含的注册页面 名字, 姓, 性别, 用户名, 密码, 电子邮件, 血型, 地址, DOB
当我尝试创建这些列表时,所有字段都不在同一页面中
我只能容纳电子邮件。其他字段(即血型,地址,Dob)不会被容纳在同一页面中。如何在同一页面中添加这些额外字段? 布局页面的代码是
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/fname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="First Name"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="@+id/efname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:singleLine="true">
<requestFocus />
</EditText>
<TextView
android:id="@+id/lname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Last Name"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="@+id/elname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:singleLine="true"/>
<TextView
android:id="@+id/rgender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Gender"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Spinner
android:id="@+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:drawSelectorOnTop="true" />
<TextView
android:id="@+id/runame"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="User Name"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="@+id/reuname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"/>
<TextView
android:id="@+id/rpass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="@+id/repass"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"/>
<TextView
android:id="@+id/email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Email"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="@+id/eemail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"/>
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"/>
<Button
android:id="@+id/cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel"
android:layout_toRightOf="@id/submit"/>
</RelativeLayout>
</LinearLayout>
</ScrollView>
答案 0 :(得分:0)
您的视图是重叠的,因为您将它们放在RelativeLayout中。如果你把它们放在相对布局之上,它们就不会。添加了一些示例字段:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/fname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:text="First Name"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="@+id/efname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:singleLine="true" >
<requestFocus />
</EditText>
<TextView
android:id="@+id/lname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:text="Address"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="@+id/elname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:singleLine="true" />
<TextView
android:id="@+id/rgender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:text="Gender"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Spinner
android:id="@+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:drawSelectorOnTop="true" />
<TextView
android:id="@+id/runame"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:text="User Name"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="@+id/reuname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp" />
<TextView
android:id="@+id/rpass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:text="Password"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="@+id/repass"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:inputType="textPassword" />
<TextView
android:id="@+id/email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:text="Email"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="@+id/eemail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:inputType="textEmailAddress" />
<TextView
android:id="@+id/email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:text="Blood Group"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="@+id/eemail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:inputType="textEmailAddress" />
<TextView
android:id="@+id/email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:text="Email"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="@+id/eemail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:inputType="textEmailAddress" />
<TextView
android:id="@+id/email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:text="Blood Group"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="@+id/eemail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:inputType="textEmailAddress" />
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:text="Submit" />
<Button
android:id="@+id/cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/submit"
android:text="Cancel" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
答案 1 :(得分:0)
试试这种方式。
在这里,我把按钮放在滚动之外。我认为在滚动视图中放置提交和取消按钮不是显示布局的便捷方式。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/fname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="First Name"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="@+id/efname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:singleLine="true">
</EditText>
<TextView
android:id="@+id/lname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Last Name"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="@+id/elname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:singleLine="true"/>
<TextView
android:id="@+id/rgender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Gender"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Spinner
android:id="@+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:drawSelectorOnTop="true" />
<TextView
android:id="@+id/runame"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="User Name"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="@+id/reuname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"/>
<TextView
android:id="@+id/rpass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="@+id/repass"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"/>
<TextView
android:id="@+id/email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Email"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="@+id/eemail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"/>
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/submit"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Submit"
android:layout_marginRight="5dp"/>
<Button
android:id="@+id/cancel"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Cancel"/>
</LinearLayout>
</LinearLayout>