2013-06-19 88 views
5

我使用的是Yuri Kanivets's WheelView control,我發現它不填充父視圖,即使佈局XML指定它執行此操作。WheelView不填充父項

這裏是我的意思圖片:

enter image description here

這裏是佈局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> 

這裏是重複/延遲查看XML(他們都是非常的相同):

<?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> 

這是我如何添加視圖:

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

    setContentView(R.layout.settings); 

      ... 

我已經通過WheelView源望去,但整個控制的寬度被設置在那裏不是很明顯,如果車輪控制好歹也是控制父佈局的寬度。

這是運行在最新的SDK上。有什麼明顯的我失蹤了?

+0

我可以看到輪子選取器和您發佈的XML之間沒有關聯。你發佈了正確的文件嗎? – Simon

+0

@Simon我添加了重複/延遲視圖XML文件。請讓我知道,如果你需要看到別的 – ZeNewb

+0

有兩個意見,一個重複和一個延遲?如果是這樣,可能會有ID衝突。 – Eric

回答

6

LinearLayout其中包含三個desiderata.ihunt.resources.WheelViewandroid:layout_width="fill_parent",但WheelViews本身具有:

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

話雖這麼說,如果我明白這個問題正確意味着,如果三個輪子的寬度小於parent的寬度(在這種情況下,LinearLayout包含三個desiderata.ihunt.resources.WheelView) - 那麼您必須將填充LinearLayout的Wheels填充爲純色(例如黑色)以隱藏其背後的內容。

+0

感謝您的明確解釋! – ZeNewb

+0

你是非常歡迎:) – g00dy

1

g00dy的替代解決方案(儘管他完全正確) - 如果將每個輪子的寬度設置爲0dp並將其設置爲layout_weight = 1,則3將伸展以佔據屏幕的相等部分。如果你不想讓它們平等,按照你想要的比例設置它們。

+0

偉大的替代品!我會試試這個 – 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> 

更改你的方向盤佈局這樣

0

嘗試這樣的佈局你的重複/延遲查看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> 

這將使小部件填滿屏幕寬度,可以調整通過調整佈局權重來調整寬度比例。如果您不需要小部件以橫向模式填充整個屏幕,則可以使用換行內容來顯示父線性佈局的寬度。