2013-06-19 2 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.WheelView имеет android:layout_width="fill_parent", но сам WheelViews есть:

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

Это, как говорится, и если я понимаю вопрос правильно означает, что если ширина три колеса меньше, что ширину parent (в данном случае LinearLayout, которая содержит три desiderata.ihunt.resources.WheelView) - тогда вам придется либо растянуть колеса, заполнить LinearLayout сплошным цветом (например, черный), чтобы скрыть то, что стоит за ним.

+0

Спасибо за четкое объяснение! – ZeNewb

+0

Вы вполне приветствуетесь :) – g00dy

1

Альтернативное решение для g00dy (хотя он совершенно прав) - если вы установите ширину каждого из колес на 0dp и установите их layout_weight = 1, они растянутся, чтобы заняться равной частью экрана. Если вы не хотите, чтобы они были равны, установите их в нужном вам соотношении.

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

Это позволит сделать виджет заполнить всю ширину экрана, и вы можете настроить ширины, путем настройки веса макета. Если вам не нужен виджет для заполнения всего экрана в ландшафтном режиме, вы можете использовать содержимое обертки для ширины родительского линейного макета.

Смежные вопросы