2014-03-25 65 views
0

我的目的是在滾動視圖上創建一個小部件列表,在它們後面的屏幕中央放置一個ImageView。這裏是我有什麼,都會有當一切都說過和做過多個按鈕:無法讓ImageView顯示

<?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="fill_parent"> 

<ImageView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:contentDescription="@string/description" 
    android:src="@drawable/myImage" 
    android:id="@+id/imageView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerInParent="true" 
    android:scaleType="centerInside" /> 


<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_centerVertical="true"   
    android:background="@android:color/transparent"> 

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center"   
     android:orientation="vertical" 
     android:background="@android:color/transparent"> 


     <Button xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/newButton" 
      style="@style/homeScreenButton" 
      android:text="@string/new_profile" /> 

     <Button xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/loadButton" 
      style="@style/homeScreenButton" 
      android:text="@string/load_profile" /> 

     <Button xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/calculatorButton" 
      style="@style/homeScreenButton" 
      android:text="@string/calculator" /> 

    </LinearLayout> 

</ScrollView> 

</RelativeLayout> 

基於Eclipse的XML圖形佈局的解釋,如預期的那樣顯示在屏幕上。我試過的兩款不同的模擬器也是如此,Android 2.2和Android 4.0.3。但是當我發送到我的實際設備時,Droid 4 w/Android 4.1.2的圖像根本不顯示。我甚至試圖讓ScrollView透明(android:alpha =「0」),認爲它以某種方式覆蓋了圖像,但沒有。任何建議將不勝感激。

回答

0

嘗試消除從ImageView的這條線,

xmlns:android="http://schemas.android.com/apk/res/android" 

應該只存在於RelativeLayout的

所以您的xml文件成爲

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 

<ImageView 
android:contentDescription="@string/description" 
android:src="@drawable/myImage" 
android:id="@+id/imageView" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_centerInParent="true" 
android:scaleType="centerInside" /> 


<ScrollView 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:layout_centerVertical="true"   
android:background="@android:color/transparent"> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:gravity="center"   
    android:orientation="vertical" 
    android:background="@android:color/transparent"> 


    <Button 
     android:id="@+id/newButton" 
     style="@style/homeScreenButton" 
     android:text="@string/new_profile" /> 

    <Button 
     android:id="@+id/loadButton" 
     style="@style/homeScreenButton" 
     android:text="@string/load_profile" /> 

    <Button 
     android:id="@+id/calculatorButton" 
     style="@style/homeScreenButton" 
     android:text="@string/calculator" /> 

</LinearLayout> 

</ScrollView> 

</RelativeLayout> 
+0

不,沒有改變,當我刪除該行。無論如何感謝您的建議。 – MrDetail

0

我想通了,代碼很好。我的問題是,圖像是/ res/drawable,但它需要在/ res/drawable-hdpi。