我每天都在使用Android,並且我想避免視圖大小的規範。 舉例來說,如果我做一個TextView
,我指定高度和寬度屬性,像這樣:有沒有辦法避免在android佈局上的大小規格?
<TextView
android:id="@+id/activity_lbl"
android:layout_width="wrap_content" <!-- Again -->
android:layout_height="wrap_content" <!--Again... --> />
<TextView
android:id="@+id/activity_lbl2"
android:layout_width="wrap_content" <!-- Again... -->
android:layout_height="wrap_content" <!--Again, for ever --> />
而對於我創建的每一個觀點,我到分配相同的規格尺寸。 有沒有辦法避免它們?
文件:RES /價值/ styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="wrapall">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
</style>
</resources>
然後將它應用到你的佈局,這樣
從文檔的layout_width和layout_height:「指定視圖的基本寬度。這是包含佈局管理器內部任何視圖的必需屬性。「http://developer.android.com/reference/android/R.styleable.html – harun