
在上面的屏幕中,我有两个线性布局,一个用于两个TextVIEw,两个EditText和其他布局用于三个按钮,如图所示,
现在我想设置这两个布局如下:
1)第一个布局需要设置在屏幕的中心
2)必须在屏幕底部设置所有按钮或第二个布局
所以我想问我怎么做到这一点.
我的XML文件是
<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:layout_wIDth="fill_parent" androID:layout_height="fill_parent" androID:orIEntation="vertical" androID:background="#000044"> <ScrollVIEw androID:ID="@+ID/scrollVIEw1" androID:layout_height="wrap_content" androID:layout_wIDth="match_parent"> <linearLayout androID:ID="@+ID/linearLayout1" androID:layout_wIDth="match_parent" androID:orIEntation="vertical" androID:layout_height="wrap_content" androID:layout_gravity="center"> <TextVIEw androID:text="Login Phone" androID:ID="@+ID/loginphone"></TextVIEw> <EditText androID:layout_height="wrap_content" androID:ID="@+ID/login" androID:layout_wIDth="match_parent" androID:text="" androID:inputType="number" androID:numeric="integer" androID:phoneNumber="true"></EditText> <TextVIEw androID:text="Mobile Pin" androID:ID="@+ID/mobilepin" ></TextVIEw> <EditText androID:layout_height="wrap_content" androID:ID="@+ID/pin" androID:inputType="number" androID:numeric="integer" androID:layout_wIDth="match_parent" androID:text="" androID:password="true"></EditText> </linearLayout> </ScrollVIEw> <linearLayout androID:ID="@+ID/linearLayout2" androID:layout_height="match_parent" androID:layout_gravity="bottom" androID:layout_wIDth="fill_parent" androID:orIEntation="horizontal" androID:gravity="bottom"> <button androID:ID="@+ID/preference" androID:text="Preferences" androID:layout_weight="1" androID:layout_height="wrap_content" androID:layout_wIDth="fill_parent"></button> <button androID:ID="@+ID/loginbutton" androID:text="Login" androID:layout_weight="1" androID:layout_height="wrap_content" androID:layout_wIDth="fill_parent"></button> <button androID:ID="@+ID/exit" androID:text="Exit" androID:layout_weight="1" androID:layout_height="wrap_content" androID:layout_wIDth="fill_parent"></button> </linearLayout> </linearLayout>解决方法:
<?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" androID:background="#000044"> <ScrollVIEw androID:ID="@+ID/scrollVIEw1" androID:layout_height="0dip" androID:layout_wIDth="fill_parent" androID:layout_weight="1"> <linearLayout androID:ID="@+ID/linearLayout1" androID:orIEntation="vertical" androID:layout_gravity="center" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content"> <TextVIEw androID:text="Login Phone" androID:layout_height="wrap_content" androID:layout_wIDth="fill_parent" androID:ID="@+ID/loginphone" /> <EditText androID:ID="@+ID/login" androID:layout_height="wrap_content" androID:layout_wIDth="fill_parent" androID:inputType="number" androID:numeric="integer" androID:phoneNumber="true" /> <TextVIEw androID:text="Mobile Pin" androID:layout_height="wrap_content" androID:layout_wIDth="fill_parent" androID:ID="@+ID/mobilepin" /> <EditText androID:ID="@+ID/pin" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" androID:inputType="number" androID:numeric="integer" androID:password="true" /> </linearLayout> </ScrollVIEw> <linearLayout androID:ID="@+ID/linearLayout2" androID:orIEntation="horizontal" androID:layout_height="wrap_content" androID:layout_wIDth="fill_parent"> <button androID:ID="@+ID/preference" androID:text="Preferences" androID:layout_weight="1" androID:layout_height="wrap_content" androID:layout_wIDth="fill_parent" /> <button androID:ID="@+ID/loginbutton" androID:text="Login" androID:layout_weight="1" androID:layout_height="wrap_content" androID:layout_wIDth="fill_parent" /> <button androID:ID="@+ID/exit" androID:text="Exit" androID:layout_weight="1" androID:layout_height="wrap_content" androID:layout_wIDth="fill_parent" /> </linearLayout></linearLayout> 总结 以上是内存溢出为你收集整理的android – 将布局组件设置为居中全部内容,希望文章能够帮你解决android – 将布局组件设置为居中所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)