This is because you set the gravity inside the TextView. But if your TextView is laid out with WRAP_CONTENT
the gravity really doesn't matter for such a short String. You should insert the TextView
inside some Layout
, specify FILL_PARENT
and setting the layout as the Dialog content view
// width is FILL_PARENT -1, height is WRAP_CONTENT -2
ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(-1, -2);
LinerLayout layout = new LinearLayout(context, params);
layout.addView(loadMsg, params);
dialog.setView(layout);
Alternatively, you can set the gravity on the layout itself and set the TextView
's width to WRAP_CONTENT