Android 安卓相对论
我对Android开发非常陌生,我正在尝试找出如何使用RelativeLayout标签来定位我的视图。我的目标是在左边有一个大的文本视图,在它的右边有两个按钮视图,它们叠在一起。下面是我正在使用的XML代码:Android 安卓相对论,android,xml,Android,Xml,我对Android开发非常陌生,我正在尝试找出如何使用RelativeLayout标签来定位我的视图。我的目标是在左边有一个大的文本视图,在它的右边有两个按钮视图,它们叠在一起。下面是我正在使用的XML代码: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/wood_tile">
<TextView
android:id="@+id/life_counter"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="00" />
<Button android:text="@string/button_up"
android:id="@+id/button_up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/life_counter"/>
<Button android:text="@string/button_down"
android:id="@+id/button_down"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/button_up"/>
</RelativeLayout>
我觉得我一定没有正确使用标签。有人能解释一下它是怎么工作的吗?提前感谢。您将左侧文本视图的宽度设置为
fill\u parent
,这将占用整个屏幕。任何放置在其右侧的内容都将脱离屏幕。使用wrap_content
或相对布局中元素的特定宽度
你的方法也有点不对劲。如果希望两个按钮与屏幕右侧对齐,请使用以下命令:
<RelativeLayout
android:id="@+id/main_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/life_counter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="00" />
<Button android:text="Button Up"
android:id="@+id/button_up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"/>
<Button android:text="Button Down"
android:id="@+id/button_down"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/button_up"/>
</RelativeLayout>
谢谢,现在所有视图都可见了!至于你的第二部分,我实际上想做的是把三个都居中,而不是分别将它们左对齐和右对齐。我还需要弄清楚如何做到这一点。要使它们居中,您需要将它们放置在一个嵌套的RelativeLayout中,该属性具有android:layout\u centerInParent=“true。请看。很漂亮。这很好。感谢您的帮助!