【发布时间】:2015-07-14 01:48:32
【问题描述】:
我在我的 Android 应用程序中使用了一些样式文件,例如:
<style name="message">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">#000000</item>
<item name="android:gravity">center_vertical</item>
<item name="android:layout_weight">1</item>
</style>
然后我使用这些样式创建一些组件:
TextView tv = new TextView(new ContextThemeWrapper(this, R.style.message));
我的问题是我注意到一些属性对我的组件没有影响,在这种情况下,layout_weight 不起作用,我必须在我的代码中指定它,如下所示:
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT);
params.weight = 1;
tv.setLayoutParams(params);
如果你有什么想法,请告诉我。
谢谢。
【问题讨论】:
-
我遇到了一些意见,认为这种程序化样式方法忽略了某些属性。因此,很有可能,没有办法避免单独设置布局参数。
标签: java android layout styles views