2015-11-07 18 views
0

在我的活動中,我有8個LinearLayout。
我想定義一個保證金所有這些(所有的人都會有相同的邊距值)如何在Activity上創建'一般保證金'

是否有可能定義「全球保證金」和每一個存在於我的活動將包含「的LinearLayout」的我在「全球利潤率」中定義的餘量?

(這將節省我的時間來定義餘量爲每個「的LinearLayout」的)

+0

我想你可以在所有這8個linearlayout的父佈局上使用填充。 – Shvet

回答

3

定義維度資源res/values,例如:

<resources>  
    <dimen name="activity_horizontal_margin">16dp</dimen> 
    <dimen name="activity_vertical_margin">16dp</dimen> 
</resources> 

然後你就可以在你的佈局XML使用每View,例如:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    tools:context=".MainActivity"> 

    <ListView 
     android:id="@+id/appsList" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"/> 

</LinearLayout> 

我建議你閱讀更多關於resources

+0

您只需將值添加爲const並將它們粘貼到LinearLayout。這不是我所尋找的 - 我需要像我們在微軟WPF ..全局屬性 – Yanshof

+1

在這種情況下,制定更好的問題,並提供更多的信息,如代碼示例或目標樣機 – NickF