当前位置: 动力学知识库 > 问答 > 编程问答 >

Android styles best practices

问题描述:

I'm not sure this is the right forum on stack to ask this, it probably needs to be in a community wiki, but I'll ask here anyways.

I've searched for this topic and have not found anything, but over the years doing Android I've come across some usages of styles that make me uncomfortable and I'd like to get some feedback on best practices regarding writing styles in Android.

One example that I feel is wrong is this style which is used for TextView in a particular layout:

<style name="historyHeroText" parent="normalText">

<item name="android:textAlignment">viewStart</item>

<item name="android:textDirection">rtl</item>

<item name="android:layout_alignParentRight">true</item>

<item name="android:gravity">right</item>

</style>

The style concerns itself with text, and alignment both regarding the inside, and outside of the element it styles. layout_alignParentRight is specific to Views that are inside of a RelativeLayout. Also, there seems to be a conflict between gravity and textAlignment which in this case both specify the same behavior.

What types of things should a style concern itself with? If it's a style meant to be used on TextView shouldn't it only concern itself with text styling and leave layout concerns for the layout file? What are some general best practices that you follow?

Also, what warrants pulling the properties out of the layout file into a style? It seems to me that if the properties are used only one place it does not warrant a style.

分享给朋友:
您可能感兴趣的文章:
随机阅读: