如何在Android中设置样式的引力?

如何在Android中设置样式的引力?,第1张

概述我有一个水平线性布局的textview,并且textview是顶部对齐的.我希望它垂直对齐.我将textview设置为一种称为“箭头”的样式<stylename="arrow"><itemname="android:textSize">30sp</item><itemname="android:textColor">#ffffff</item>&

我有一个水平线性布局的textvIEw,并且textvIEw是顶部对齐的.我希望它垂直对齐.

我将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>

爪哇

            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);

但是,这仍然不能使其垂直对齐…

有人知道这是怎么回事吗?

谢谢

解决方法:

setTextAppearance()的javadocs状态:

Sets the text color, size, style, hint color, and highlight color from
the specifIEd TextAppearance resource.

@H_502_35@

其中不包括任何有关位置或重力的信息.我想这就是为什么你的引力没有作用的原因.

尝试这样:

//for androID:gravityarrow.setGravity(Gravity.CENTER);//for androID:layout_gravitylinearLayout.LayoutParams params = new linearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);params.gravity=Gravity.CENTER;arrow.setLayoutParams(params);

就是说,由于您的TextVIEw的宽度和高度为WRAP_CONTENT,因此androID:gravity不会产生任何影响.因此,实际上androID:layout_gravity代码块应该是您所需要的.

总结

以上是内存溢出为你收集整理的如何在Android中设置样式的引力?全部内容,希望文章能够帮你解决如何在Android中设置样式的引力?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1075870.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存