android - 避免在 android 中重复 fill_parent & wrap_content & match_parent

标签 android android-layout android-styles

我有很多

android:layout_width="fill_parent"

&

android:layout_height="wrap_content"

我的应用程序项目中的属性。所以我想以如下样式添加它们。

<style name="layout_wf_hw">
    <item name="android:layout_width">fill_parent</item>
    <item name="android:layout_height">wrap_content</item>
</style>
<style name="layout_ww_hw">
    <item name="android:layout_width">wrap_content</item>
    <item name="android:layout_height">wrap_content</item>
</style>

样式.xml

<style name="inputbox" parent="layout_wf_hw">
    <item name="android:background">@drawable/editviewstyle</item>
</style>

现在我的代码 View 是

<EditText style="@style/inputbox"/>

我的问题是我们可以这样申请吗?这是我遵循的正确方法吗?

谢谢

最佳答案

我没有看到您的代码中不允许的任何内容。

其实我觉得是尊重DRY原则,这是一件好事。

唯一令人恼火的是,对于其他开发人员来说,第一次理解和阅读它可能有点困难。

所以我的回答是:为什么不。

关于android - 避免在 android 中重复 fill_parent & wrap_content & match_parent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16978949/

相关文章:

Android 表 UI 元素

php - android restful webservice将数据数组发送到php并在服务器中检索数据

Android如何增加评分栏中星星的高度和宽度

android - TextView和其他TextView挤压时的Ellipsize

android-如何更改我的编辑文本和微调器的样式

android - 如何删除android Activity 标签( Activity 标题)和标签栏?

android - 如何在 Android 中查找内容提供商的调用 Activity ?

android - 当我的应用程序在后台运行时,如何让android系统杀死它?

java - 在 Android 中设置视频作为背景播放

Android 图表与其他内容在同一页面中