I have a custom dialogue with the list. When you first start the dialogue, the indents in height are ignored and some of the elements are not visible. On subsequent launches, everything is in order . I have no idea what can help in solving the problem, I bring a bunch of different code, it may come in handy.
Dialog code:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <ListView android:id="@+id/lvMultiChoice" android:divider="@color/backgr" android:dividerHeight="1dp" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:drawSelectorOnTop="false" android:layout_width="match_parent" android:layout_height="wrap_content" > </ListView> </LinearLayout> 

The button is put in the list's footer, in fact, usually it’s not visible (partially visible):

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="wrap_content" android:layout_width="match_parent" android:orientation="horizontal"> <Button android:id="@+id/btnDialogOk" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="OK" android:layout_weight="1" android:background="@drawable/button_grey" android:layout_marginTop="10dp" android:layout_marginBottom="10dp" /> </LinearLayout> 

I create a dialogue like this:

 dialogMultiChoice = new Dialog(this,R.style.AppTheme_Dialog); dialogMultiChoice.setContentView(R.layout.dialog_multichoice); ListView lvMultiChoice = (ListView) (dialogMultiChoice.findViewById(R.id.lvMultiChoice)); View v = getLayoutInflater().inflate(R.layout.lv_footer_btn_ok, null); lvMultiChoice.addFooterView(v,null,false); dialogMultiChoice.getWindow().setTitleColor(getResources().getColor(R.color.backgr)); dialogMultiChoice.setTitle(Fragment_Filter.adapterFilter.names[id]); adapMeal = new MultiChoiceAdapter(Samo_Data.MEAL); lvMultiChoice.setAdapter(adapMeal); dialogMultiChoice.getWindow().setLayout(lp.width, lp.height); return dialogMultiChoice; 

The topic that is used when creating the dialogue:

 <style name="AppTheme.DialogTitle"> <item name="android:textSize">16pt</item> <item name="android:textColor"> @android :color/black</item> <item name="android:gravity">center</item> </style> <style name="AppTheme.DialogWindowTitle"> <item name="android:maxLines">1</item> <item name="android:textAppearance"> @style /AppTheme.DialogTitle</item> </style> <style name="AppTheme.Dialog"> <item name="android:windowTitleStyle"> @style /AppTheme.DialogWindowTitle</item> </style> 
  • Try replacing margin with pading - andreich
  • Does not help - tayrinn

1 answer 1

I do not know, the topic is complex - it is difficult to advise something concrete. To be honest, I see it for the first time - so that the first launch was different from the subsequent one? Some kind of mysticism.

The only thing I see here is a small footnote in the documentation:

Dialog class for dialogs, but you should avoid instantiating Dialog directly.

In your code, the Dialog constructor is called directly, that is, what is not recommended ...

I would advise you to create your own class descendant from Dialog or as DialogFrame is now recommended - there will be much more control, in particular, when you first create a dialog, you will receive a callback on Activity.onCreateDialog() , on the second and subsequent calls to Activity.onPrepareDialog() .

  • Wow A lot of things need to be rewritten. Later I will accomplish my goal, at least some advice, otherwise I’m completely misunderstood. PS You, of course, meant DialogFragment? Or something I do not understand? - tayrinn
  • Yes, of course, DialogFragment - Barmaley
  • I rewrote. The result is absolutely amazing. Now, with each opening right in front of my eyes, the dialogue slightly “jumps” and its height increases by the missing margins. O_O - tayrinn