2011-10-27 37 views
5

Tôi đang sử dụng RelativeLayout để đặt Chế độ xem. Bây giờ tôi muốn thêm một Chế độ xem khác bên dưới Chế độ xem đầu tiên và sẽ được căn giữa được gọi là Chế độ xem đầu tiên. Nhưng có vẻ như không có tùy chọn thats được gọi là một cái gì đó như android: layout_alignCenter .. Làm thế nào tôi có thể đạt được nhiệm vụ này?Chế độ xem trung tâm bên dưới một Chế độ xem khác

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

      <TextView 
     android:text="Blaa" 
     android:id="@+id/TextView1" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_marginLeft="100dp" 
     android:gravity="center" 
     /> 
      <TextView 
     android:text="Foo" 
     android:id="@+id/TextView2" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:layout_below="@+id/TextView1" 
      --- NEED STH THAT ALIGNS THIS SECOND VIEW CENTRAL UNDER THE FIRST VIEW -- 
     /> 
</RelativeLayout> 
+1

alignParentCenter ... – Warpzit

+0

Điều đó sẽ sắp xếp Xem tôi trung tâm trong các phụ huynh, nhưng tôi muốn sắp xếp nó-xăng tập trung sang Xem thứ hai - Xin lỗi câu hỏi là một chút mơ hồ – Salo

+0

Với 'android: gravity =" center "' bạn có cả hai trung tâm, do đó TextView2 được đặt ở giữa TextView1. – iCantSeeSharp

Trả lời

0

Tôi cũng đã tìm kiếm câu trả lời. Tôi nghĩ rằng lựa chọn tốt nhất là đặt chúng vào LinearLayout .. Tôi không chắc chắn nhưng tôi tin rằng lạm phát rất nhiều bố trí là một quá trình chuyên sâu vì vậy nó có lẽ không phải là lựa chọn tốt nhất nhưng đó là điều duy nhất tôi có thể nghĩ đến.

2

Đây là một câu hỏi cũ, nhưng vẫn chưa được trả lời, vì vậy ...

Bạn có thể có cả hai đầu và kết thúc của cả hai quan điểm thẳng hàng trong cùng một cách. Điều này sẽ ghi đè lên thuộc tính chiều rộng của thuộc tính thứ hai và sẽ làm cho nó rộng như là đầu tiên, nhưng cũng sẽ di chuyển nó với thuộc tính đầu tiên. Nếu bạn muốn căn giữa chế độ xem thứ hai, bạn có thể sử dụng lực hấp dẫn hoặc phần đệm. Quan điểm thứ hai đi vậy:

<TextView 
    android:id="@+id/TextView2" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:layout_below="@+id/TextView1" 
    android:layout_alignLeft="@+id/TextView1" 
    android:layout_alignRight="@+id/TextView1" 
    android:gravity="center" 
    android:text="Foo" /> 
0
<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:gravity="top" > 

    <TextView 
     android:id="@+id/TextView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_marginLeft="100dp" 
     android:gravity="center" 
     android:text="Blaa" /> 

    <RelativeLayout 
     android:id="@+id/rel_main" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/TextView1" 
     android:layout_alignRight="@+id/TextView1" 
     android:layout_below="@+id/TextView1" 
     android:gravity="center" > 

     <TextView 
      android:id="@+id/TextView2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerInParent="true" 
      android:text="Foo" /> 
    </RelativeLayout> 

</RelativeLayout> 
Các vấn đề liên quan