2016-03-28 21 views
0

6つのNumberPickerと2つのボタンを含むポップアップダイアログを作成しようとしています。以下は XMLコードです:私の問題は、(それが実際に画面に表示されdoesntの)赤にここに見られるように、最後のNumberPickerは、ダイアログのエッジ消灯ということです 私が使用Androidのダイアログの内容が一致しません

<LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/np" 
     android:layout_centerHorizontal="true"> 

     <NumberPicker 
      android:id="@+id/numberPicker1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="32dp" 
      android:descendantFocusability="blocksDescendants"/> 

     <NumberPicker 
      android:id="@+id/numberPicker2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="32dp" 
      android:descendantFocusability="blocksDescendants"/> 

     <NumberPicker 
      android:id="@+id/numberPicker3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="32dp" 
      android:descendantFocusability="blocksDescendants"/> 

     <NumberPicker 
      android:id="@+id/numberPicker4" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="32dp" 
      android:descendantFocusability="blocksDescendants"/> 

     <NumberPicker 
      android:id="@+id/numberPicker5" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="32dp" 
      android:descendantFocusability="blocksDescendants"/> 

     <NumberPicker 
      android:id="@+id/numberPicker6" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="32dp" 
      android:descendantFocusability="blocksDescendants"/> 
    </LinearLayout> 

    <Button 
     android:id="@+id/button1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Set" 
     android:layout_below="@+id/np" 
     android:layout_alignParentEnd="true" /> 

    <Button 
     android:id="@+id/button2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Cancel" 
     android:layout_below="@+id/np" 
     android:layout_alignParentStart="true" /> 

</RelativeLayout> 

とコードで単純に:

final Dialog dialog = new Dialog(EditTextActivity.this); 
     dialog.setContentView(R.layout.registration_picker_dialog); 
     dialog.setTitle("Edit Year"); 

NumberPickersの幅を縮小するためにXMLには何かがありますか?

+0

「NumberPicker」ごとに、「layout_width」を「0dp」に、「layout_weight」を「1」に設定します。 –

答えて

1

各NumberPickerでは、layout_weight属性を使用して、各コントロールにコンテナの1/6を割り当てます。

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/np" 
    android:layout_centerHorizontal="true" 
    android:weightSum="1.0"> <!-- Added weightSum --> 

    <!-- added layout_weight --> 
    <NumberPicker android:layout_weight="0.167" 
     android:id="@+id/numberPicker1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="32dp" 
     android:descendantFocusability="blocksDescendants"/> 

    <!-- added layout_weight --> 
    <NumberPicker android:layout_weight="0.167" 
     android:id="@+id/numberPicker2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="32dp" 
     android:descendantFocusability="blocksDescendants"/> 

    <!-- added layout_weight --> 
    <NumberPicker android:layout_weight="0.167" 
     android:id="@+id/numberPicker3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="32dp" 
     android:descendantFocusability="blocksDescendants"/> 

    <!-- added layout_weight --> 
    <NumberPicker android:layout_weight="0.167" 
     android:id="@+id/numberPicker4" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="32dp" 
     android:descendantFocusability="blocksDescendants"/> 

    <!-- added layout_weight --> 
    <NumberPicker android:layout_weight="0.167" 
     android:id="@+id/numberPicker5" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="32dp" 
     android:descendantFocusability="blocksDescendants"/> 

    <!-- added layout_weight --> 
    <NumberPicker android:layout_weight="0.167" 
     android:id="@+id/numberPicker6" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="32dp" 
     android:descendantFocusability="blocksDescendants"/> 
</LinearLayout> 
+1

問題ありません。ありがとう。 – EJK

+0

ありがとうございました。私はそれを私のためにすべて緊密に詰めるだろうという印象の下にあったが、私はjavax.swingに関してあまり考えすぎるかもしれない – mike73

関連する問題