2015-05-19 54 views
0

派生視圖的所有屬性這是我layout.xml派生從styles.xml所有視圖參數Android的佈局XML文件應該從styles.xml

<?xml version="1.0" encoding="utf-8"?> 
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res /android" 
    android:layout_width="match_parent" 
    style="@style/DataContainer"> 

    <ImageView 
     android:id="@id/df_flight_logo" 
     style="@style/FlightLOGO" 
     /> 


    <TextView 
    android:id="@id/flight_name" 
     style="@style/FlightName" 
     /> 

    <TextView 
    android:id="@id/flight_price" 
     style="@style/FlightPrice" 
     />  

    </RelativeLayout> 

這是我styles.xml

<resources> 

    <!-- Base application theme. --> 
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
     <!-- Customize your theme here. --> 
    </style> 

    <style name="DataContainer"> 
     <item name="android:layout_height">125dp</item> 
     <item name="android:background">#ffffff</item> 
    </style> 

    <style name="FlightLOGO"> 
     <item name="android:layout_height">25dp</item> 
     <item name="android:layout_weight">25dp</item> 
     <item name="android:background">@drawable/background</item> 
    </style> 

    <style name="FlightName"> 
     <item name="android:layout_height">32dp</item> 
     <item name="android:background">#b2b2b2</item> 
    </style> 

    <style name="FlightPrice"> 
     <item name="android:layout_height">12dp</item> 
     <item name="android:layout_marginLeft">18dp</item> 
     <item name="android:background">#b2b2b2</item> 
    </style> 


</resources> 

所以我應該把所有的視圖屬性(寬度,高度,邊距,填充)到styles.xml?或特定視圖(按鈕樣式,文本樣式)屬性爲styles.xml?

回答

0

根據你的評論解釋你正在嘗試做什麼,你應該使用維度。他們像字符串一樣是資源。

<resources> 
    <dimen name="title_size">32sp</dimen> 
</resources> 

再舉例來說,使用與TextView

<TextView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:textSize="@dimen/title_size"/> 

現在你有不同的dimens.xml文件不同的屏幕尺寸,但佈局保持一致!

一個例子是這裏

http://android4beginners.com/2013/07/appendix-c-everything-about-sizes-and-dimensions-in-android/

+0

通過將所有的屬性都syles.xml,我想用同樣的layout.xml爲不同尺寸的設備。對不同大小的設備有不同的styles.xml。這種設計方法好嗎? –

+0

@AnilKushwaha我已編輯 –

+0

這是我的文本視圖這是我的styles.xml