【发布时间】:2015-12-28 09:59:47
【问题描述】:
我正在运行时创建一个 LinearLayout,我在其中添加了两个元素:一个文本视图和一个微调器。 我想在 LinearLayout 中将它们水平居中,但不知道该怎么做。下面是我用来创建视图的代码:
LinearLayout leftSideAttributLayout = new LinearLayout(this);
leftSideAttributLayout.setOrientation(LinearLayout.HORIZONTAL);
LinearLayout.LayoutParams attributLayoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
leftSideAttributLayout.setLayoutParams(attributLayoutParams);
LinearLayout.LayoutParams leftLabelParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
leftLabelParams.gravity = Gravity.CENTER;
leftAttributLabel.setLayoutParams(leftLabelParams);
TextView leftAttributLabel = new TextView(this);
leftAttributLabel.setText(attribut.getNom());
leftAttributLabel.setTextColor(Color.WHITE);
Tools.applyFont(getApplicationContext(), leftAttributLabel, "gothic_0.TTF");
LinearLayout.LayoutParams spinnerParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
spinnerParams.gravity = Gravity.CENTER_HORIZONTAL;
spinnerParams.setMargins(10, 0, 0, 0);
Spinner leftAttributValues = new Spinner(this);
leftAttributValues.setLayoutParams(spinnerParams);
leftAttributValues.setAdapter(adapter);
leftAttributValues.setBackgroundResource(R.drawable.lenti_attributspinner);
leftAttributValues.setTag(attribut);
如果有人可以帮助我,那就太好了!谢谢:)
【问题讨论】:
标签: android android-layout position android-linearlayout center