2013-08-29 19 views
0

我試圖將按鈕下方的一些文本居中,但出於某種原因出現在按鈕頂部。有什麼建議麼?我真的不確定可能會導致這種情況。試圖在按鈕下方居中文本 - Android

我可以根據需要上傳屏幕截圖。

來源:

<?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="match_parent" 
    android:background="@drawable/background" 
    android:orientation="vertical" > 

    <View 
     android:id="@+id/view1" 
     android:layout_width="match_parent" 
     android:layout_height="35dp" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:layout_weight="1" /> 

    <ImageView 
     android:id="@+id/emblem" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_centerVertical="true" 
     android:gravity="center" 
     android:scaleType="fitStart" 
     android:src="@drawable/apn_app_logo" /> 

    <Button 
     android:id="@+id/go_button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_centerVertical="true" 
     android:layout_marginRight="54dp" 
     android:background="@drawable/apn_app_go_button" /> 

    <TextView 
     android:id="@+id/text" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/go_button" 
     android:layout_align="@+id/go_button" 
     android:layout_alignParentRight="true" 
     android:text="@string/start_text2" 
     android:textColor="#000000" 
     android:textSize="14sp" /> 

</RelativeLayout> 
+2

'的android :layout_align'看起來不像一個有效的屬性,你可以嘗試刪除該行嗎? –

+0

雅,'android:layout_align'只接受像'center_vertical'等值。刪除,你應該很好。 – Don

+0

另外,你在'View'標籤上設置了一個'layout_weight'。此標籤只能用於'LinearLayout'的子項。 – Don

回答

1

只是改變你的代碼了一下,希望對你的作品

<TextView android:id="@+id/text" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/go_button" 
     android:layout_alignRight="@+id/go_button" 
     android:layout_below="@+id/go_button" 
     android:textColor="#000000" 
     android:gravity="center" 
     android:textSize="14sp" /> 
0

嘗試添加重力來獲取文本居中:

 <TextView android:id="@+id/text" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignLeft="@+id/go_button" 
      android:layout_alignRight="@+id/go_button" 
      android:layout_below="@+id/go_button" 
      android:textColor="#000000" 
      android:gravity="center" 
      android:textSize="14sp" />