Android 为什么我的对话框中的搜索栏在方向为水平时绘制不正确? 关闭:不可复制。
在对应用程序进行看似无关的更改后,问题自行解决了 我正在使用的应用程序要求用户设置绘制对象的笔划宽度。为此,我创建了一个自定义对话框 在垂直方向上,对话框看起来很好 然而,在水平方向上,SeekBar有点混乱 SeekBar功能正常,只是线条和进度条绘制不正确 下面是我用来创建所用视图的代码Android 为什么我的对话框中的搜索栏在方向为水平时绘制不正确? 关闭:不可复制。,android,android-layout,seekbar,android-dialogfragment,Android,Android Layout,Seekbar,Android Dialogfragment,在对应用程序进行看似无关的更改后,问题自行解决了 我正在使用的应用程序要求用户设置绘制对象的笔划宽度。为此,我创建了一个自定义对话框 在垂直方向上,对话框看起来很好 然而,在水平方向上,SeekBar有点混乱 SeekBar功能正常,只是线条和进度条绘制不正确 下面是我用来创建所用视图的代码 private View createView() { LinearLayout linearLayout = new LinearLayout(getActivity()); linear
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在任一方向正确显示