2012-07-13 35 views
5

tôi đã bố trí sau:layout_height = "fill_parent" trong RelativeLayout không hoạt động

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/item_background" 
    android:layout_margin="10dip" 
    android:gravity="center_vertical"> 

    <View 
     android:layout_width="30dip" 
     android:layout_height="fill_parent" 
     android:background="@color/test_color"/> 

    <ImageView 
     android:id="@+id/task_item_startstop_button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/start_task" 
     android:layout_centerVertical="true" 
     android:focusable="false" 
     android:background="#0000"/> 

    <View 
     android:id="@+id/task_item_line" 
     android:layout_width="2dp" 
     android:layout_height="40dip" 
     android:layout_margin="5dip" 
     android:background="@color/line_color" 
     android:layout_toRightOf="@id/task_item_startstop_button"/> 

    <TextView 
     android:id="@+id/task_item_title" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:textColor="@android:color/black" 
     android:textSize="22sp" 
     android:textStyle="bold" 
     android:layout_toRightOf="@id/task_item_line" /> 

    <TextView 
     android:id="@+id/task_item_status" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/task_item_suspended" 
     android:textSize="18sp" 
     android:textColor="@android:color/black" 
     android:layout_toRightOf="@id/task_item_line" 
     android:layout_below="@id/task_item_title"/> 

    <TextView 
     android:id="@+id/task_item_timer" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="5dip" 
     android:textSize="18sp" 
     android:textColor="@android:color/black" 
     android:layout_toRightOf="@id/task_item_status" 
     android:layout_below="@id/task_item_title"/> 

</RelativeLayout> 

Tôi muốn có đường thẳng đứng (xem đầu tiên bên trong bố trí root) vào ngày trái bố trí với chiều rộng cố định và chiều cao bình đẳng chiều cao của cha mẹ. Nhưng nếu tôi đặt layout_height = "fill_parent" thì nó không giúp ích gì. Chiều cao là 0. Nếu tôi thiết lập chiều cao ví dụ 40dip, nó sẽ là 40 dip. Nhưng tôi cần chính xác thuộc tính fill_parent.

+0

thực sự bạn muốn làm gì? – AkashG

+0

Bạn có thể đăng bản vẽ những gì bạn muốn đạt được không? –

+0

Hãy thử điều này, sử dụng android: layout_alignParentLeft = "true" cho View của bạn và sau đó thiết lập task_item_startstop_button liên quan đến nó. Đưa ra một id để ure Xem – Shubhayu

Trả lời

0

Điều này có khắc phục được sự cố của bạn không? Chỉ cần thay thế các yếu tố có liên quan bằng chính riêng bạn

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

     <Button 
      android:layout_height="match_parent" 
      android:layout_width="30dp" 
      android:id="@+id/thebutton" 
      android:text="hello world" 
      /> 

    <AnalogClock 
     android:id="@+id/analogClock1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_toRightOf="@+id/thebutton" /> 

</RelativeLayout> 
-1

bạn đã đặt lề cho bố cục tương đối của bố mẹ bạn, đó là lý do tại sao bạn thêm bất kỳ thứ gì luôn mang lại lợi nhuận cho tiện ích của mình. Xóa android: layout_margin = "10dip" khỏi bố cục tương đối cha mẹ của bạn, sau đó bạn có dòng có trong tệp cha mẹ.

+0

không hoạt động những gì bạn thực sự đã nói ở đây. –

Các vấn đề liên quan