2012-09-11 23 views
0

我不明白爲什麼沒有出現我的代碼。一切都是使用線性佈局設置的,我習慣於這種線性佈局,但是在編譯和運行代碼時沒有任何影響。 (在日誌中也沒有錯誤)我確信我只是在查看一些簡單的東西。爲什麼佈局沒有出現在Android?

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="#000000" > 

    <LinearLayout 
     android:id="@+id/itemprofilelayout" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:weightSum="100" 
     android:orientation="vertical" 
     android:background="@android:color/transparent" > 

     <LinearLayout 
      android:id="@+id/toplayout" 
      android:layout_width="fill_parent" 
      android:layout_height="0dp" 
      android:layout_weight="30" 
      android:orientation="horizontal" 
      android:background="@android:color/transparent" > 

      <ImageView 
       android:id="@+id/itempicture" 
       android:contentDescription=" " 
       android:layout_width="0dp" 
       android:layout_height="fill_parent" 
       android:background="#FFFFFF" 
       android:src="@drawable/budlight_sample" /> 

      <TextView 
       android:id="@+id/iteminformation" 
       android:layout_width="0dp" 
       android:layout_height="fill_parent" 
       android:background="#FFFFFF" /> 
     </LinearLayout> 

     <LinearLayout 
      android:id="@+id/middlelayout" 
      android:layout_width="fill_parent" 
      android:layout_height="0dp" 
      android:layout_weight="30" 
      android:orientation="horizontal" 
      android:background="@android:color/transparent" > 

      <TextView 
       android:id="@+id/socialoptions" 
       android:layout_width="0dp" 
       android:layout_height="fill_parent" 
       android:background="#FFFFFF"/> 

      <TextView 
       android:id="@+id/map" 
       android:layout_width="0dp" 
       android:layout_height="fill_parent" 
       android:background="#FFFFFF" /> 
     </LinearLayout> 

     <TextView 
      android:id="@+id/itemratings" 
      android:layout_width="fill_parent" 
      android:layout_height="15dp" 
      android:layout_weight="1" 
      android:background="#FFFFFF" /> 

     <TextView 
      android:id="@+id/itemreviews" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="25" 
      android:background="#FFFFFF" /> 

    </LinearLayout> 

</ScrollView> 

活動:

package My.Taste.App; 

import android.app.Activity; 
import android.os.Bundle; 

public class ItemListActivity extends Activity{ 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.itemlist); 
    } 
} 
+1

你能張貼實際的代碼,你用它來顯示這個佈局文件? –

+0

我發佈了它。感謝您的幫助。 – jrquick

+0

我認爲itemlist是你顯示的XML文件的名稱?另外你的XML文件編譯?你可以在eclipse設計視圖中查看它嗎? – Doomsknight

回答

0

解決通過改變代碼的上半部分有以下問題:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/itemprofilestartup" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="#000000" 
    android:orientation="vertical" > 

    <LinearLayout 
     android:id="@+id/toplayout" 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_weight="30" 
     android:background="@android:color/transparent" 
     android:gravity="top" 
     android:orientation="horizontal" 
     android:paddingLeft="0dp" > 
4

我以前從未使用過的MapView。但它不是一個標準的Android設備上查看,請嘗試使用全名:

<com.google.android.maps.MapView 
    ... /> 

但是,如果這不是問題,你也有很多設置爲0dplayout_width屬性。當我將ImageView的寬度更改爲wrap_content時,它顯示正常。你也不會看到你的任何TextView,因爲你還沒有傳遞任何文本。

+0

你說的MapView是問題的一部分,同時改變了wrap_content使視圖可見,但是當改變0dp時,權重不再起作用,這意味着佈局設置不正確。 – jrquick

+0

因此,將寬度更改爲'wrap_content'會影響您的'layout_weights'? – Sam

+0

它使它們不再有效。在我之前的佈局中,當我將layout_widhth或layout_height從0dp更改爲wrap_content時,會導致佈局完全更改。就這樣,當我改變寬度屬性時,儘管有權重,視圖尺寸也發生了變化。例如:id/itemprofile突然佔據屏幕的大部分,而不是通過權重分配給它的30%。 – jrquick

相關問題