我有一个水平线性布局的textview,并且textview正在顶部对齐。我希望它垂直对齐。如何在android中设置风格的重力?
我TextView的设置为一个名为式的 “箭头”
<style name="arrow">
<item name="android:textSize">30sp</item>
<item name="android:textColor">#ffffff</item>
<item name="android:textStyle">bold</item>
<item name="android:gravity">center</item>
<item name="android:layout_gravity">center</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
</style>
的Java
LinearLayout LL = new LinearLayout(this);
LL.setOrientation(LinearLayout.HORIZONTAL);
LL.setPadding(15, 15, 15, 15);
LinearLayout.LayoutParams courseMargin = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
courseMargin.setMargins(5, 5, 5, 5);
LL.setLayoutParams(courseMargin);
// here I add more things into LL...
TextView arrow = new TextView(this);
arrow.setText(">");
arrow.setTextAppearance(this, R.style.arrow);
LL.addView(arrow);
然而,这仍不能使其垂直对齐......
有谁知道这是怎么回事?
感谢
将代码发布到包含textview的布局xml文件中 – FoamyGuy
我使用java代码创建它。我把它贴在上面。 – omega