0

我有以下XML爲什麼我的relativeLayout不會出現在它的兄弟linearLayout之下?

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@color/blue_bg"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center_horizontal" 
     android:orientation="vertical" > 

     <com.my.view.text.MyTextView 
      android:id="@+id/whyResgisterHeaderText" 
      style="@style/textOnBg" 
      android:layout_marginTop="25dp" 
      android:text="WHY REGISTER?" 
      android:textStyle="bold" /> 

     <com.my.view.text.MyTextView 
      android:id="@+id/whyResgisterBodyText" 
      style="@style/textOnBg" 
      android:text="Help us keep your account safe" 
      android:textStyle="normal" /> 

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="10dp" 
      android:layout_marginTop="5dp" 
      android:src="@drawable/signup_illu_why" /> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center" > 

      <Button 
       android:id="@+id/gotItButton" 
       android:layout_width="250dp" 
       android:layout_height="50dp" 
       android:layout_gravity="center" 
       android:layout_marginTop="5dp" 
       android:background="@drawable/btn_selector" 
       android:padding="0dp" /> 

      <com.my.view.text.MyTextView 
       android:id="@+id/gotItText" 
       style="@style/textOnBg" 
       android:layout_marginTop="25dp" 
       android:text="Got it" 
       android:textColor="#00bcfe" 
       android:textSize="16dp" 
       android:textStyle="italic" /> 
     </RelativeLayout> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:orientation="vertical" > 

     <View 
      android:layout_width="match_parent" 
      android:layout_height="1dp" 
      android:background="#70a5b3" /> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" > 

      <com.my.view.text.MyTextView 
       style="@style/textOnBg" 
       android:layout_toLeftOf="@+id/skipIcon" 
       android:text="Skip" 
       android:textStyle="normal" /> 

      <ImageView 
       android:id="@id/skipIcon" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentTop="true" 
       android:src="@drawable/signup_skip_icon" /> 
     </RelativeLayout> 
    </LinearLayout> 

</RelativeLayout> 

我想我的屏幕看起來像:

enter image description here

但它看起來像:

enter image description here

1)爲什麼我不能請參閱fotter relativeLayout(使用「跳過」)

2)我怎麼能中心gotItText textView?爲什麼它不是以當前屬性爲中心?

+0

在我的IDE中,如果我將自定義的TextView更改爲默認的TextView並刪除所有樣式,它將按照您的要求工作。 –

+0

嘗試通過xml,並檢查RelativeLayout的佈局高度屬性,即「wrap_content」,它是子LinearLayout(其中包括「skip」具有alignParent)。這本身就是矛盾的。將頂部RelativeLayout的屬性設置爲「match_parent」。讓我知道,如果這個作品! –

回答

0

因爲你的根佈局是一個RelativeLayout。

您應該爲第一個LinearLayout聲明一個ID,然後在第二個LinearLayout上使用layout_below屬性。請記住,他們的位置是親戚,所以如果你沒有指定第二個Linear的位置,它將被繪製在第一個上面。

如果您希望獲得一個低於另一個的線性自動使用LinearLayout作爲主根。

0

編輯你的代碼,取代了自定義的EditTexts,並刪除了樣式,爲佈局設置了新的高度,並且它看起來像你想要的那樣工作。

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center_horizontal" 
     android:orientation="vertical" > 

     <TextView 
      android:id="@+id/whyResgisterHeaderText" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="25dp" 
      android:text="WHY REGISTER?" 
      android:textStyle="bold" /> 

     <TextView 
      android:id="@+id/whyResgisterBodyText" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Help us keep your account safe" 
      android:textStyle="normal" /> 

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="10dp" 
      android:layout_marginTop="5dp" /> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center" > 

      <Button 
       android:id="@+id/gotItButton" 
       android:layout_width="250dp" 
       android:layout_height="50dp" 
       android:layout_gravity="center" 
       android:layout_marginTop="5dp" 
       android:padding="0dp" /> 

      <TextView 
       android:id="@+id/gotItText" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="25dp" 
       android:text="Got it" 
       android:textColor="#00bcfe" 
       android:textSize="16dp" 
       android:textStyle="italic" /> 

     </RelativeLayout> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:orientation="vertical" > 

     <View 
      android:layout_width="match_parent" 
      android:layout_height="1dp" 
      android:background="#70a5b3" /> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" > 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_toLeftOf="@+id/skipIcon" 
       android:text="Skip" 
       android:textStyle="normal" /> 

      <ImageView 
       android:id="@id/skipIcon" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentTop="true" /> 
     </RelativeLayout> 
    </LinearLayout> 

</RelativeLayout> 
相關問題