我正在使用带有 2 个文本视图、4 个按钮、1 个搜索栏、1 个图像视图的线性布局。如果我将这些文本视图、按钮等放在线性布局中,则在 android 手机中对齐很好。虽然我在 android 平板电脑上运行相同的代码,但对齐不正确。为什么这种对齐在平板电脑中不正确。?我已经通过 java 代码创建了文本视图、按钮等。即使我通过devicewidth/2设置第二个文本视图的左边距来水平指定两个文本视图,这在 android 手机和平板电脑中存在差异。我需要像下面这样对齐。
 TextView1                            TextView2
 Button1 Button2 Button3 Button4      SeekBar  ImageView
这是我的代码。
 LinearLayout.LayoutParams textViewParams1 = new LinearLayout.LayoutParams(
             LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    textViewLayout.setOrientation(LinearLayout.HORIZONTAL); 
    TextView TextView1=new TextView(this);
    TextView1.setText("Text1");
    textViewParams1.gravity=Gravity.CENTER;
    textViewParams1.setMargins(60, 20, 40, 10);
    textViewLayout.addView(chooseColorTextView, textViewParams1);
    LinearLayout.LayoutParams textViewParams2 = new LinearLayout.LayoutParams(
             LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    TextView TextView2=new TextView(this);
    TextView2.setText("Text2");
    int width=getWindowManager().getDefaultDisplay().getWidth();
    textViewParams2.gravity=Gravity.CENTER;     
    textViewParams2.setMargins((width/2), 20, 40, 10);
    textViewLayout.addView(strokeWidthTextView, textViewParams2);
    parentlinearLayout.addView(textViewLayout, textViewLayoutParams);
在下一个线性布局中,我添加了 4 个按钮、搜索栏和图像视图。但面临对齐问题。