我需要一个大于屏幕的用户表单.布局由固定的“标题区域”,表单(可能在滚动视图中)和底部的按钮组成.我创建了三个布局,中间的布局是ScrollVIEw,它具有垂直方向的linearLayout.不幸的是,表格将按钮推离了屏幕?!
有一个简单的例子可以做到这一点吗?
我想我可以使用ListVIEw,但是我认为ScrollVIEw更易于管理.这是我的布局…
<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:orIEntation="vertical" androID:layout_wIDth="fill_parent" androID:layout_height="fill_parent" > <!-- Title Area on top --> <linearLayout androID:ID="@+ID/layout_form" androID:orIEntation="vertical" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" > <linearLayout androID:orIEntation="horizontal" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" > <ImageVIEw androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_margintop="0dip" androID:layout_marginBottom="0dip" androID:paddingtop="20dip" androID:paddingBottom="20dip" androID:paddingleft="5dip" androID:paddingRight="10dip" androID:src="@drawable/logo" androID:layout_gravity="center" androID:layout_weight="1" /> <TextVIEw androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_gravity="center" androID:layout_weight="2" androID:layout_margintop="0dip" androID:layout_marginBottom="0dip" androID:layout_marginleft="4dip" androID:layout_marginRight="4dip" androID:text="@string/Title_create" /> </linearLayout> <!-- Form entry on top --> <ScrollVIEw androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" androID:fillVIEwport="true" androID:clipChildren="true" > <linearLayout androID:orIEntation="vertical" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" > <TextVIEw androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" androID:layout_gravity="center_horizontal" androID:layout_marginleft="8dip" androID:layout_marginRight="8dip" androID:text="@string/label_fIEld_one" /> <EditText androID:ID="@+ID/edit_fIEld_one" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" androID:singleline="true" androID:layout_marginleft="10dip" androID:layout_marginRight="10dip" androID:hint="@string/hint_fIEld_one" /> <TextVIEw androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" androID:layout_gravity="center_horizontal" androID:layout_marginleft="8dip" androID:layout_marginRight="8dip" androID:text="@string/label_fIEld_two" /> <EditText androID:ID="@+ID/edit_fIEld_two" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" androID:singleline="true" androID:layout_marginleft="10dip" androID:layout_marginRight="10dip" androID:hint="@string/hint_fIEld_two" /> <!-- Repeat label-text and edit-text until done ... --> </linearLayout> </ScrollVIEw> <!-- "spring" between form and wizard buttons. --> <linearLayout androID:layout_wIDth="fill_parent" androID:layout_height="0dp" androID:layout_weight="1" /> <linearLayout androID:orIEntation="horizontal" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" androID:layout_gravity="left" androID:layout_weight="2" > <button androID:ID="@+ID/btn_submit" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_gravity="right" androID:layout_weight="1" androID:text="@string/button_submit" /> </linearLayout> </linearLayout></linearLayout>
解决方法:
如果我理解正确,这是很常见的事情-具有固定的页眉和页脚,并在中间填充任何内容(在您的情况下为ScrollVIEw).那是您要找的东西吗?如果是这样,您将想尝试以下方法:
<relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:layout_wIDth="fill_parent" androID:layout_height="fill_parent" > <linearLayout androID:ID="@+ID/header" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" androID:layout_alignParenttop="true" > //.....stuff here </linearLayout> <linearLayout androID:ID="@+ID/footer" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" androID:layout_alignParentBottom="true" > //.....stuff here </linearLayout> <ScrollVIEw androID:layout_wIDth="fill_parent" androID:layout_height="fill_parent" androID:layout_above="@ID/footer" androID:layout_below="@ID/header" > //......stuff here </ScrollVIEw></relativeLayout>
基本上,您定义一个标头,给它一个固定的高度(在这种情况下为wrap_content),并将其设置为与父级的顶部对齐(relativeLayout).然后,对页脚执行相同 *** 作,将其与父级底部对齐.您可以根据自己的情况在页脚中仅用button代替linearLayout,也可以将按钮放在linearLayout内.在没有额外的linearLayout的情况下,填充布局可能会更快一些.但是无论如何,接下来,定义您的表单,即滚动区域.将高度设置为fill_parent,并告诉它在页脚上方和页眉下方.这将导致它占用页眉和页脚之间的所有剩余空间.
总结以上是内存溢出为你收集整理的如何布置可在Android SDK中滚动的表单?全部内容,希望文章能够帮你解决如何布置可在Android SDK中滚动的表单?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)