gpt4 book ai didi

java - 如何使样式中的 Layout_margin 在 java 中工作

转载 作者:太空狗 更新时间:2023-10-29 15:27:50 26 4
gpt4 key购买 nike

我在 styles.xml 中有一个带有边距参数的样式,但是当我使用它时它不起作用。

<style name="detailTitreEntree" parent="@android:style/Widget.TextView">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">@color/red</item>
<item name="android:textSize">12sp</item>
<item name="android:textStyle">bold</item>
<item name="android:layout_margin">10dip</item>
</style>

我想在我的 java 代码中使用这种样式,所以我已经这样做了:

TextView tvEntree = new TextView(getApplicationContext());
tvEntree.setText("hello");
tvEntree.setTextAppearance(getApplicationContext(),R.style.detailTitreEntree);
myLayout.addView(tvEntree);

颜色、样式和尺寸都可以,但边距不起作用。可以用我的风格做到这一点吗?

抱歉我的英语不好

最佳答案

查看此问题的答案:Layout problem with button margin .解决方案应该是一样的。

关于java - 如何使样式中的 Layout_margin 在 java 中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6665506/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com