2011-08-11 47 views
0

我只想做一個ImageView的作爲我headbar ...它應該只是填寫他的父母線性佈局..顯然事實並非如此。ImageView的(「headbar」)不同的屏幕等

有沒有辦法告訴scaleType只是爲了適應它的父佈局? (XML中的最佳解決方案)我看到的是一個編程解決方案,其設置scaleType「補」 ......但似乎沒有匹配的XML屬性,或者我沒有看到嗎?

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 
    <LinearLayout 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" 
     android:layout_weight="1" 
     android:id="@+id/linearlayoutmain"> 
    <ImageView 
     android:layout_marginTop="0dp" 
     android:src="@drawable/headbar" 
     android:id="@+id/mainheadbar" 
     android:scaleType="fitStart" 
     android:paddingTop="0dp" 
     android:layout_height="fill_parent" 
     android:layout_width="fill_parent" 
     /> 
    </LinearLayout> 
    <LinearLayout 
     android:layout_height="fill_parent" 
     android:layout_width="fill_parent" 
     android:layout_weight="7" 
     android:layout_below="@id/linearlayoutmain"> 
    </LinearLayout> 
</RelativeLayout> 

有關它的任何想法/解決方案?我想我不需要介意長寬比,因爲我9patched整個事情..所以應該不會介意。

編輯:它似乎工作更好,當我使用ImageBUtton而不是ImageView ...但是,我在小尺寸屏幕上遇到問題...他們似乎不介意我的9patching ...大聲笑

回答

1

你需要在一般

  1. 佈局華電國際使用三種類型的佈局

  2. 佈局MDPI

  3. 佈局LDPI

而且你需要在一般

  1. 值,華電國際

  2. 價值觀MDPI

  3. 價值觀LDPI

使用三個值佈局她的EI爲LDPI設備標題說明你有你設備華電國際,MDPI做,等

例如簡單的XML有圖片爲頭:佈局LDPI - 頁眉

<?xml version="1.0" encoding="UTF-8"?> 
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="fill_parent" android:layout_height="50px" 
      android:orientation="horizontal" > 

    <ImageView android:id="@+id/header_main_title" android:layout_marginTop="10dip" 
       android:layout_width="wrap_content" android:layout_height="50dip" 
       android:background="@drawable/header_image" 
       android:layout_centerHorizontal="true" android:layout_marginRight="10dip" 
       /> 

同樣值-LDPI包含

<?xml version="1.0" encoding="utf-8"?> 

    <resources> 
    <style name="MyTheme" parent="android:Theme"> 
     <item name="android:windowTitleSize">50px</item> 
     <item name="android:windowTitleBackgroundStyle">@style/WindowTitleBackground 
     </item>  
    </style> 
    </resources> 

類似地,對於Styles.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<resources> 
<style name="WindowTitleBackground" parent="android:WindowTitleBackground"> 
    <item name="android:background">@android:color/transparent</item> 
</style> 

在你的Manifest.xml包括此行:

<application android:icon="@drawable/vmi_icon" android:label="@string/app_name" android:theme="@style/MyTheme" > 

把Styles.xml和主題。價值觀LDPI文件夾內

我出標題爲LDPI設備同樣需要創建MDPI華電國際設備XML

變化應在該行的所有

的進行如果是華電國際:

<item name="android:windowTitleSize">100px</item> 

如果它是MDPI:

<item name="android:windowTitleSize">70px</item> 

同樣,對於header.xml:

如果是華電國際:

android:layout_height="100px" 

如果它是MDPI:

android:layout_height="70px" 

讓我知道如果你需要進一步澄清。 謝謝Venky。

+0

如果MDPI設備70dp將正確安裝。 – Venky

+0

感謝第一個地方..也許你可以幫我解決我的第二個問題.. http://stackoverflow.com/questions/7030772/9patching-cant-have-more-than-one-marked-region-along-邊緣 – Aeefire