2013-06-19 47 views
5

Tôi đang sử dụng Yuri Kanivets's WheelView control và tôi thấy rằng nó không được điền vào chế độ xem gốc mặc dù XML bố cục xác định nó để làm như vậy.WheelView không điền cha mẹ

Dưới đây là hình ảnh của những gì tôi có nghĩa là:

enter image description here

Dưới đây là cách bố trí XML:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="#00000000"> 

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

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      android:paddingTop="5dp" 
      android:paddingBottom="5dp" 
      android:background="@drawable/picker_bar"> 
      <Button 
       android:id="@+id/repeatButton" 
       android:textColor="#FFF"     
       android:layout_gravity="center_vertical" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:background="@drawable/picker_button_selected" 
       android:paddingTop="8dp" 
       android:paddingBottom="8dp" 
       android:paddingLeft="15dp" 
       android:paddingRight="15dp" 
       android:layout_marginLeft="7dp" 
       android:gravity="center" 
       android:textSize="16sp" 
       android:text="Repeat"/> 
      <Button 
       android:id="@+id/DelayButton" 
       android:layout_gravity="center_vertical" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:background="@drawable/picker_button_unselected" 
       android:paddingTop="8dp" 
       android:textColor="#FFF" 
       android:paddingBottom="8dp" 
       android:paddingLeft="15dp" 
       android:paddingRight="15dp" 
       android:layout_marginLeft="10dp" 
       android:gravity="center" 
       android:textSize="16sp"   
       android:text="Delay"/> 
      <Button 
       android:id="@+id/doneButton" 
       android:layout_marginLeft="10dp" 
       android:layout_gravity="center_vertical" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:background="@drawable/picker_button_unselected" 
       android:textColor="#FFF" 
       android:paddingTop="8dp" 
       android:paddingBottom="8dp" 
       android:paddingLeft="15dp" 
       android:paddingRight="15dp" 
       android:gravity="center" 
       android:textSize="16sp" 
       android:text="Done"/>    
     </LinearLayout> 

     <include layout="@layout/repeat_view"/> 
     <include layout="@layout/delay_view"/> 
    </LinearLayout> 
</RelativeLayout> 

Dưới đây là quan điểm lặp lại/chậm trễ XML (cả hai đều khá nhiều giống nhau):

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/wheelRepeat" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:background="@drawable/layout_bg" 
    android:layout_width="fill_parent"> 
    <LinearLayout 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:layout_width="fill_parent" 
     android:paddingTop="4dp" 
     android:paddingBottom="4dp"  
     android:orientation="horizontal"> 
     <desiderata.ihunt.resources.WheelView 
      android:id="@+id/activeRepeat" 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:layout_gravity="center_vertical" 
      android:layout_weight="1"/>    
     <desiderata.ihunt.resources.WheelView 
      android:id="@+id/minsRepeat" 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:layout_gravity="center_vertical" 
      android:layout_weight="2"/> 
     <desiderata.ihunt.resources.WheelView 
      android:id="@+id/secsRepeat" 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:layout_gravity="center_vertical" 
      android:layout_weight="2"/>     
    </LinearLayout> 
</LinearLayout> 

Đây là cách tôi thêm chế độ xem:

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    setContentView(R.layout.settings); 

      ... 

Tôi đã xem qua nguồn WheelView, nhưng không rõ độ rộng của toàn bộ điều khiển đang được đặt và điều khiển bánh xe bằng cách nào đó cũng kiểm soát chiều rộng của bố cục gốc.

Điều này đang chạy trên SDK mới nhất. Có điều gì rõ ràng mà tôi đang bỏ lỡ không?

+0

Tôi không thể thấy kết nối giữa bộ chọn bánh xe và XML bạn đã đăng. Bạn đã đăng đúng tệp chưa? – Simon

+0

@Simon Tôi đã thêm các tệp XML xem lại/trì hoãn. Vui lòng cho tôi biết nếu bạn cần xem bất kỳ điều gì khác – ZeNewb

+0

Có hai chế độ xem, một chế độ xem để lặp lại và một lần cho sự chậm trễ không? Nếu vậy, có thể có xung đột ID. – Eric

Trả lời

6

Các LinearLayout trong đó có ba desiderata.ihunt.resources.WheelViewandroid:layout_width="fill_parent", nhưng WheelViews mình có:

android:layout_height="wrap_content" 
android:layout_width="wrap_content" 

đó đang được nói và nếu tôi hiểu câu hỏi nghĩa một cách chính xác, rằng nếu chiều rộng của ba Bánh xe là ít mà chiều rộng của parent (trong trường hợp này là LinearLayout trong đó có ba desiderata.ihunt.resources.WheelView) - sau đó bạn sẽ phải hoặc là strech các bánh xe điền vào các LinearLayout với một màu (ví dụ đen) để ẩn những gì đằng sau nó.

+0

Cảm ơn bạn đã giải thích rõ ràng! – ZeNewb

+0

Bạn đang khá hoan nghênh :) – g00dy

1

Giải pháp thay thế cho g00dy (mặc dù anh ấy hoàn toàn đúng) - nếu bạn đặt chiều rộng của mỗi bánh xe thành 0dp và đặt layout_weight = 1, 3 sẽ kéo dài để chiếm một phần bằng nhau của màn hình. Nếu bạn không muốn chúng bằng nhau, hãy đặt chúng theo tỷ lệ bạn muốn.

+0

Thay thế tuyệt vời! Tôi sẽ thử – ZeNewb

0
<LinearLayout 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:layout_width="fill_parent" 
     android:paddingTop="4dp" 
     android:weightSum="3"  // add weight sum here 
     android:paddingBottom="4dp"  
     android:orientation="horizontal"> 
     <desiderata.ihunt.resources.WheelView 
      android:id="@+id/activeRepeat" 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:layout_gravity="center_vertical" 
      android:layout_weight="1"/>    //weights here 
     <desiderata.ihunt.resources.WheelView 
      android:id="@+id/minsRepeat" 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:layout_gravity="center_vertical" 
      android:layout_weight="1"/>    //weights here 
     <desiderata.ihunt.resources.WheelView 
      android:id="@+id/secsRepeat" 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:layout_gravity="center_vertical" 
      android:layout_weight="1"/>    //weights here  
    </LinearLayout> 

Thay đổi bố cục bánh xe của bạn như thế này

0

Hãy thử một cách bố trí như thế này để chơi lại/chậm trễ của bạn xem xml

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/wheelRepeat" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:background="@drawable/layout_bg" 
    android:layout_width="fill_parent"> 
    <LinearLayout 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:layout_width="fill_parent" 
     android:paddingTop="4dp" 
     android:paddingBottom="4dp"  
     android:orientation="horizontal" 
     android:weightSum="10"> 

     <desiderata.ihunt.resources.WheelView 
      android:id="@+id/activeRepeat" 
      android:layout_height="wrap_content" 
      android:layout_width="0dp" 
      android:layout_gravity="center_vertical" 
      android:layout_weight="2"/>    
     <desiderata.ihunt.resources.WheelView 
      android:id="@+id/minsRepeat" 
      android:layout_height="wrap_content" 
      android:layout_width="0dp" 
      android:layout_gravity="center_vertical" 
      android:layout_weight="4"/> 
     <desiderata.ihunt.resources.WheelView 
      android:id="@+id/secsRepeat" 
      android:layout_height="wrap_content" 
      android:layout_width="0dp" 
      android:layout_gravity="center_vertical" 
      android:layout_weight="4"/>     
    </LinearLayout> 
</LinearLayout> 

Điều này sẽ làm widget choán hết chiều rộng màn hình và bạn có thể điều chỉnh tỷ lệ chiều rộng bằng cách điều chỉnh trọng lượng bố cục. Trong trường hợp bạn không cần tiện ích để lấp đầy toàn màn hình ở chế độ ngang, bạn có thể sử dụng nội dung bọc cho chiều rộng của bố cục tuyến tính gốc.

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