Android RelativeLayout:为什么我的按钮不显示在线条下方?

Android RelativeLayout:为什么我的按钮不显示在线条下方?,android,android-layout,android-relativelayout,Android,Android Layout,Android Relativelayout,在我的RelativeLayout中,我试图在屏幕的后半部分设置两个按钮 在我使用视图创建的线下方 但该行下方不会显示按钮(view1) 这是我的XML: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:lay

在我的RelativeLayout中,我试图在屏幕的后半部分设置两个按钮

在我使用视图创建的线下方

但该行下方不会显示按钮(
view1

这是我的XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bgland"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MenuActivity" >

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:scaleType="fitXY"
    android:src="@drawable/white_bg" />

<EditText
    android:id="@+id/bikenumber"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/getbikebutton"
    android:layout_centerHorizontal="true"
    android:layout_marginLeft="20dip"
    android:layout_marginRight="20dip"
    android:layout_marginTop="20dip"
    android:ems="10"
    android:hint="@string/hint_getbike"
    android:inputType="number"
    android:singleLine="true" >

    <requestFocus />
</EditText>

<Button
    android:id="@+id/getbikebutton"
    style="@style/OrangeButtonStyle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/view1"
    android:layout_alignLeft="@+id/view1"
    android:layout_alignRight="@+id/view1"
    android:layout_marginBottom="10dip"
    android:layout_marginLeft="15dip"
    android:layout_marginRight="15dip"
    android:text="@string/menu_getbikebuttontext" />

<View
    android:id="@+id/view1"
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:layout_centerInParent="true"
    android:layout_margin="20dip"
    android:background="@android:color/darker_gray" />

<Button
    android:id="@+id/buttonGoToMyLoc"
    style="@style/OrangeButtonStyle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/view1"
    android:layout_alignRight="@+id/view1"
    android:layout_below="@+id/view1"
    android:layout_marginBottom="10dip"
    android:layout_marginLeft="15dip"
    android:layout_marginRight="15dip"
    android:text="@string/menu_text_near_me" />

<Button
    android:id="@+id/buttonGoToThisLoc"
    style="@style/OrangeButtonStyle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/view1"
    android:layout_alignRight="@+id/view1"
    android:layout_below="@+id/buttonGoToMyLoc"
    android:layout_marginLeft="15dip"
    android:layout_marginRight="15dip"
    android:layout_marginTop="10dip"
    android:text="@string/menu_text_address" />

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignTop="@+id/imageView1"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="25dip"
    android:text="@string/menu_title"
    android:textColor="@android:color/black"
    android:textSize="20dip"
    android:textStyle="bold" />

<EditText
    android:id="@+id/locAddress"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/imageView1"
    android:layout_alignRight="@+id/imageView1"
    android:layout_below="@+id/textView1"
    android:layout_centerHorizontal="true"
    android:layout_marginLeft="20dip"
    android:layout_marginRight="20dip"
    android:layout_marginTop="10dip"
    android:ems="10"
    android:hint="@string/menu_hint"
    android:inputType="text"
    android:singleLine="true"
    android:visibility="gone" >

    <requestFocus />
</EditText>

<EditText
    android:id="@+id/locAddressCity"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/imageView1"
    android:layout_alignRight="@+id/imageView1"
    android:layout_below="@+id/locAddress"
    android:layout_centerHorizontal="true"
    android:layout_marginLeft="20dip"
    android:layout_marginRight="20dip"
    android:ems="10"
    android:hint="@string/menu_hint_city"
    android:inputType="text"
    android:singleLine="true"
    android:visibility="gone" />

</RelativeLayout>

这是图形化的结果:正如您所看到的,这两个按钮位于中间线(
view1
)的上方(而不是下方,应该是这样)


您必须在RelativeLayout上设置android:layout\u height=“match\u parent”。然后它将知道所有可用的地方,并将VIEW1置于中间。


或者您可以将
android:layout_放置在view1的下方=“@+id/getbikebutton”

或者您必须在RelativeLayout上设置
android:layout_height=“match_parent”
。然后它将知道所有可用的地方,并将VIEW1置于中间。

或者您可以将android:layout_放在view1的下面=“@+id/getbikebutton”。

您写道:

   android:layout_above="@+id/view1"
但要引用另一个视图,必须在不使用“+”的情况下进行,如下所示:

   android:layout_above="@id/view1"
    <View
android:id="@+id/view1"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_centerInParent="true"
android:layout_margin="20dip"
android:background="@android:color/darker_gray" />

    <Button
android:id="@+id/getbikebutton"
style="@style/OrangeButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/view1"
android:layout_alignLeft="@+id/view1"
android:layout_alignRight="@+id/view1"
android:layout_marginBottom="10dip"
android:layout_marginLeft="15dip"
android:layout_marginRight="15dip"
android:text="@string/menu_getbikebuttontext" />


   <Button
android:id="@+id/buttonGoToMyLoc"
style="@style/OrangeButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/view1"
android:layout_alignRight="@+id/view1"
android:layout_below="@id/view1"
android:layout_marginBottom="10dip"
android:layout_marginLeft="15dip"
android:layout_marginRight="15dip"
android:text="@string/menu_text_near_me" />
此外,您必须首先创建视图,因为第一个按钮不能引用未创建的视图。布局的一部分应如下所示:

   android:layout_above="@id/view1"
    <View
android:id="@+id/view1"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_centerInParent="true"
android:layout_margin="20dip"
android:background="@android:color/darker_gray" />

    <Button
android:id="@+id/getbikebutton"
style="@style/OrangeButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/view1"
android:layout_alignLeft="@+id/view1"
android:layout_alignRight="@+id/view1"
android:layout_marginBottom="10dip"
android:layout_marginLeft="15dip"
android:layout_marginRight="15dip"
android:text="@string/menu_getbikebuttontext" />


   <Button
android:id="@+id/buttonGoToMyLoc"
style="@style/OrangeButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/view1"
android:layout_alignRight="@+id/view1"
android:layout_below="@id/view1"
android:layout_marginBottom="10dip"
android:layout_marginLeft="15dip"
android:layout_marginRight="15dip"
android:text="@string/menu_text_near_me" />

您写道:

   android:layout_above="@+id/view1"
但要引用另一个视图,必须在不使用“+”的情况下进行,如下所示:

   android:layout_above="@id/view1"
    <View
android:id="@+id/view1"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_centerInParent="true"
android:layout_margin="20dip"
android:background="@android:color/darker_gray" />

    <Button
android:id="@+id/getbikebutton"
style="@style/OrangeButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/view1"
android:layout_alignLeft="@+id/view1"
android:layout_alignRight="@+id/view1"
android:layout_marginBottom="10dip"
android:layout_marginLeft="15dip"
android:layout_marginRight="15dip"
android:text="@string/menu_getbikebuttontext" />


   <Button
android:id="@+id/buttonGoToMyLoc"
style="@style/OrangeButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/view1"
android:layout_alignRight="@+id/view1"
android:layout_below="@id/view1"
android:layout_marginBottom="10dip"
android:layout_marginLeft="15dip"
android:layout_marginRight="15dip"
android:text="@string/menu_text_near_me" />
此外,您必须首先创建视图,因为第一个按钮不能引用未创建的视图。布局的一部分应如下所示:

   android:layout_above="@id/view1"
    <View
android:id="@+id/view1"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_centerInParent="true"
android:layout_margin="20dip"
android:background="@android:color/darker_gray" />

    <Button
android:id="@+id/getbikebutton"
style="@style/OrangeButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/view1"
android:layout_alignLeft="@+id/view1"
android:layout_alignRight="@+id/view1"
android:layout_marginBottom="10dip"
android:layout_marginLeft="15dip"
android:layout_marginRight="15dip"
android:text="@string/menu_getbikebuttontext" />


   <Button
android:id="@+id/buttonGoToMyLoc"
style="@style/OrangeButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/view1"
android:layout_alignRight="@+id/view1"
android:layout_below="@id/view1"
android:layout_marginBottom="10dip"
android:layout_marginLeft="15dip"
android:layout_marginRight="15dip"
android:text="@string/menu_text_near_me" />



使用线性布局,然后元素在彼此下面。

使用线性布局,然后元素在彼此下面。

@Lisa您的xml错误,请使用线性布局或正确使用相对布局。@pratik hi pratik,为什么不对?你没有使用正确的相对论惯例Lisa@LisaAnne你到底做了没有?@pratik我认为使用+符号没有问题。她遇到的问题是relativeLayout有一个wrap_内容高度,她使用布局来定位元素_above@Lisa您的xml错误,请使用线性布局或正确使用相对布局。@pratik hi pratik,为什么不对?你没有使用正确的相对论惯例Lisa@LisaAnne你到底做了没有?@pratik我认为使用+符号没有问题。她遇到的问题是relativeLayout有一个wrap\u内容高度,她使用上面的布局定位元素。你可以像下面的布局一样尝试=“@id/view1”@schopy谢谢你schopy,设置
android:layout\u height=“match\u parent”
成功了!!!谢谢!您可以像下面的布局一样尝试=“@id/view1”@schopy谢谢schopy,设置
android:layout\u height=“match\u parent”
成功了!!!谢谢!放置+符号表示视图可以在被引用后显示放置+符号表示视图可以在被引用后显示