如何使用RelativeLayout的我实现以下目的? [英] How do I achieve the following result using RelativeLayout?
本文介绍了如何使用RelativeLayout的我实现以下目的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
图片:<一href="http://img838.imageshack.us/img838/1402/picse.png">http://img838.imageshack.us/img838/1402/picse.png
如何使PIC中的布局。 2使用RelativeLayout的而已。下面是第一张截图的XML布局。
&LT; XML版本=1.0编码=UTF-8&GT?;
&LT; RelativeLayout的
的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT&GT;
&LT;的TextView
机器人:ID =@ + ID / timer_textview
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:重力=中心
机器人:layout_marginTop =10dip
机器人:TEXTSIZE =30sp
机器人:layout_alignParentTop =真
机器人:文本=@字符串/ timer_start/&GT;
&LT;的ListView
机器人:ID =@ + ID / questions_listview
机器人:layout_below =@ ID / timer_textview
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =FILL_PARENT/&GT;
&LT;按钮机器人:ID =@ + ID / true_btn
机器人:文本=@字符串/ true_option
机器人:layout_alignParentBottom =真
机器人:layout_weight =1
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT/&GT;
&LT;按钮
机器人:ID =@ + ID / false_btn
机器人:文本=@字符串/ false_option
机器人:layout_toRightOf =@ ID / true_btn
机器人:layout_alignBaseline =@ ID / true_btn
机器人:layout_weight =1
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT/&GT;
&LT; / RelativeLayout的&GT;
解决方案
您可以使用的LinearLayout
底部实现这一目标。但是,要使用 RelativeLayout的
布局只有这样:
&LT; RelativeLayout的机器人:layout_width =FILL_PARENT...&GT;
...
&LT;查看机器人:ID =@ + ID /帮手
机器人:layout_width =0dp
机器人:layout_height =0dp
机器人:layout_alignParentBottom =真
机器人:layout_centerHorizontal =真/&GT;
&LT;按钮机器人:ID =@ + ID / true_btn
机器人:layout_alignParentBottom =真
机器人:layout_alignParentLeft =真
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_toLeftOf =@ ID /帮手/&GT;
&LT;按钮
机器人:ID =@ + ID / false_btn
机器人:layout_alignBaseline =@ ID / true_btn
机器人:layout_alignParentRight =真
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_toRightOf =@ ID /帮手/&GT;
&LT; / RelativeLayout的&GT;
你不能真正使用嵌套布局?
Pictures: http://img838.imageshack.us/img838/1402/picse.png
How do I make the layout in Pic. 2 using RelativeLayout ONLY. Below is the xml layout of the first screenshot.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/timer_textview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="10dip"
android:textSize="30sp"
android:layout_alignParentTop="true"
android:text="@string/timer_start" />
<ListView
android:id="@+id/questions_listview"
android:layout_below="@id/timer_textview"
android:layout_width="wrap_content"
android:layout_height="fill_parent" />
<Button android:id="@+id/true_btn"
android:text="@string/true_option"
android:layout_alignParentBottom="true"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="@+id/false_btn"
android:text="@string/false_option"
android:layout_toRightOf="@id/true_btn"
android:layout_alignBaseline="@id/true_btn"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
解决方案
You could use LinearLayout
at bottom to achieve this. But you want to use RelativeLayout
layout only so:
<RelativeLayout android:layout_width="fill_parent" ... >
...
<View android:id="@+id/helper"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
<Button android:id="@+id/true_btn"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/helper"/>
<Button
android:id="@+id/false_btn"
android:layout_alignBaseline="@id/true_btn"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/helper" />
</RelativeLayout>
Can't you really use nested layouts?
这篇关于如何使用RelativeLayout的我实现以下目的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文