0

I'm trying to align right text in my dialog. How can I do that ? I've tried to:

TextView loadMsg = new TextView(context);
loadMsg.setText("טוען...");
loadMsg.setGravity(Gravity.RIGHT);       
dialog.setView(loadMsg);
dialog.show();

But the text does not show.

4

3 に答える 3

4

Sub-way: Create a sub layout and set content view by this dialog.setContentView(R.layout.dialog_layout);

And design the sub layout the way you like :D

于 2012-04-07T18:23:52.493 に答える
1

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

于 2012-04-07T18:25:29.510 に答える
0

Maybe you are missing LayoutParams in which you have to define heigh and width. If you use wrap_content for width then it would not be aligned as there will no be any extra space.

于 2012-04-07T18:25:33.523 に答える