2017-12-12 3 views
0

大画面でアプリケーションを起動すると、DatePickerDialogの右側に余分なスペースがあります。ダイアログのDatePickerDialogの空白を削除するには?

ソースコード:

val datePicker = DatePickerDialog.OnDateSetListener { 
view, year, monthOfYear, dayOfMonth -> if (view.isShown) { 
myCalendar.set(Calendar.YEAR, year) 
myCalendar.set(Calendar.MONTH, monthOfYear) 
myCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth) 
addTimer(isAct) 
} 
} 
DatePickerDialog(this, datePicker, myCalendar!! .get(Calendar.YEAR), myCalendar!!.get(Calendar.MONTH), myCalendar.get(Calendar.DAY_OF_MONTH)).show() 

誰かがそれを調整する方法を言うことができますか? thx screen

+0

使用している場合は、ピッカーの表示に使用するコードを投稿してくださいスタイルや何かポストそれだけでなく – elmorabea

+0

'valの日付ピッカー= DatePickerDialog.OnDateSetListener {ビュー、今年、monthOfYear、DAYOFMONTHは - > 場合(view.isShown){ myCalendar.set(Calendar.YEAR、年) myCalendar.set( Calendar.MONTH、monthOfYear) myCalendar.set(Calendar.DAY_OF_MONTH、DAYOFMONTH) addTimer(isAct) }} DatePickerDialog(この、日付ピッカー、myCalendar! myCalendar.get(Calendar.DAY_OF_MONTH))。show() '()は、 –

答えて

0

レイアウトパラメタをラップコンテンツとして設定して、日付選択ダイアログの空白を削除することができます。ダイアログはウィンドウの中央に表示されます。 コンテンツに

android:layout_width="wrap_content"をラップする

マッチ親としてview--

protected void makeWrapContent(View v) { 

    View current = v;   
    do { 
     // Get the parent 
     ViewParent parent = current.getParent();  

     // Check if the parent exists 
     if (parent != null) { 
      // Get the view 
      try { 
       current = (View) parent; 
      } catch (ClassCastException e) { 
       break; 
      } 

      // Modify the layout 
      current.getLayoutParams().width = LayoutParams.WRAP_CONTENT; 
     } 
    } while (current.getParent() != null); 

    // Request a layout to be re-done 
    current.requestLayout(); 
} 
0

変更XMLファイルのラップコンテンツを作るために、このワン

@Override 
public void onStart() { 
    // This MUST be called first! Otherwise, the view tweaking will not be present in the displayed Dialog (most likely overridden) 
    super.onStart(); 

    makeWrapContent(myCustomView); 
} 

に簡単な方法を試してみてください