0

我试图在 OnPreExecute 方法中将右重力设置为线性布局,但对话框仍然在左侧显示我的希伯来文文本。我的代码有什么问题?

private ProgressDialog dialog;
    private Context context;
    private LinearLayout layout;

    public MyTask(Activity activity) {
        context = activity;
        dialog = new ProgressDialog(context);
        layout = new LinearLayout(context);
    }

    protected void onPreExecute() {           
        ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(-1, -2);             
        layout.setGravity(Gravity.RIGHT);
        TextView loadMsg = new TextView(context);
        loadMsg.setText("טוען...");
        loadMsg.setGravity(Gravity.RIGHT);
        layout.addView(loadMsg, params);
        dialog.setView(layout);         
    //  dialog.setContentView(R.layout.loaddialog);
    //   dialog.show();
    }
4

1 回答 1

2

我已尝试解决您的问题尝试使用它。它对我有用。

    LinearLayout lp = new LinearLayout(getApplicationContext());
    lp.setMinimumWidth(100);
    ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    lp.setGravity(Gravity.RIGHT);
    TextView loadMsg = new TextView(this);
    loadMsg.setText("my msg");
    loadMsg.setTextColor(Color.WHITE);
    loadMsg.setGravity(Gravity.RIGHT);
    lp.addView(loadMsg, params);
    Dialog dialog = new Dialog(this);
    dialog.setContentView(lp);
    dialog.show();
于 2012-04-21T12:51:26.400 回答