Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

avoid duplicate fill_parent & wrap_content & match_parent in android

I have many of

android:layout_width="fill_parent"

&

android:layout_height="wrap_content"

properties in my app project. So i would like to add them in styles like the below.

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

styles.xml

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

Now my code view is

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

My question is can we apply like this? Is this right way what i followed?

Thanks

like image 564
Pavan Kumar Avatar asked Mar 16 '26 23:03

Pavan Kumar


1 Answers

I don't see anything which is not allowed in your code.

Actually I think it's respecting DRY principle, and that's a good thing.

The only thing which might be annoying is that maybe it's a little bit more difficult to understand and read for other developers on the first time.

So my answer is: why not.

like image 120
Aerilys Avatar answered Mar 18 '26 11:03

Aerilys



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!