当方向水平时,为什么我的对话框中的SeekBar未正确绘制?

时间:2015-03-11 14:31:43

标签: android android-layout seekbar android-dialogfragment

  

已关闭:不可重复。

     

在对应用程序进行看似无关的更改后,问题已经解决。

我正在处理的应用程序要求用户为Paint对象设置StrokeWidth。为此,我创建了一个自定义对话框。

在垂直方向,对话框看起来很好。

Custom Dialog in Vertical Orientation

然而,在水平方向上,SeekBar有点混乱。

Custom Dialog in Horizontal Orientation

SeekBar功能正常,只是线条和进度条没有正确绘制。

这是我用来创建使用的视图的代码。

private View createView() {
    LinearLayout linearLayout = new LinearLayout(getActivity());
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    LinearLayout.LayoutParams linearLayoutParams= new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, 
            LinearLayout.LayoutParams.MATCH_PARENT
    );
    linearLayoutParams.setMargins(0,0,0,0);
    linearLayout.setLayoutParams(linearLayoutParams);

    this.lineDrawView = new LineDrawView(getActivity());
    LinearLayout.LayoutParams lineDrawLayoutParams = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, 
            LinearLayout.LayoutParams.WRAP_CONTENT
    );
    lineDrawLayoutParams.setMargins(25,25,25,0);
    lineDrawView.setMaximumStrokeWidth(this.maximum_stroke_width);
    lineDrawView.setStrokeWidth(this.stroke_width);
    linearLayout.addView(lineDrawView, lineDrawLayoutParams);

    this.seekBar = new SeekBar(getActivity());
    LinearLayout.LayoutParams seekbarLayoutParams = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, 
            LinearLayout.LayoutParams.WRAP_CONTENT
    );
    seekbarLayoutParams.setMargins(0, 0, 0, 0);
    seekBar.setMax((int)this.maximum_stroke_width);
    seekBar.setPadding(64,64,64,84);
    seekBar.setOnSeekBarChangeListener(this);
    seekBar.setProgress((int)this.stroke_width);
    linearLayout.addView(seekBar, seekbarLayoutParams);

    return linearLayout;
}

创建对话框的代码

public Dialog onCreateDialog(Bundle bundle) {
    View view = createView();
    this.alertDialog = new AlertDialog.Builder(getActivity())
            .setTitle(this.titleId)
            .setView(view)
            .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    onStrokeWidthChanged();
                }
            })
            .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            }).create();
    return this.alertDialog;
}

如何让SeekBar在任一方向正确显示?

0 个答案:

没有答案