设置布局的重力

时间:2012-04-21 12:07:04

标签: android android-layout android-ui

我正在尝试将正确的引力设置为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();
    }

1 个答案:

答案 0 :(得分:1)

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

    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();