2011-03-13 85 views
0

我有一個線性佈局與各種項目的活動,但是當我運行應用程序我沒有得到任何顯示。活動沒有顯示

請幫忙:-)

<LinearLayout 
    mlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" android:layout_height="fill_parent"> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="horizontal" 
     android:layout_width="fill_parent" 
     android:layout_height="50px" 
     android:id="@+id/TitleBarLayOut" 
     android:background="@drawable/titlebar_gradient"> 
    </LinearLayout> 
    <LinearLayout android:id="@+id/topLayout" android:layout_width="fill_parent" android:layout_height="70px" android:background="#FFFFFF"> 
    <ImageView android:id="@+id/coverArt" android:layout_width="60px" android:layout_height="60px" android:paddingLeft="10px" android:paddingTop="10px"></ImageView> 
    <TextView android:layout_width="fill_parent" android:id="@+id/playlistTitle" android:text="TextView" android:layout_height="30px"></TextView> 
    <TextView android:layout_width="fill_parent" android:id="@+id/playlistMember" android:text="TextView" android:layout_height="30px"></TextView> 
    </LinearLayout> 
    <LinearLayout android:id="@+id/bottomLayout" android:layout_width="fill_parent" android:layout_height="70px" android:background="#FFFFFF"> 
    <TextView android:layout_width="fill_parent" android:id="@+id/playlistDescriptions" android:text="TextView" android:layout_height="fill_parent"></TextView> 
    </LinearLayout> 
</LinearLayout> 

setContentView(R.layout.playlistview); 

Display display = getWindowManager().getDefaultDisplay(); 
int screenWidth = display.getWidth(); 

LinearLayout titlebar = (LinearLayout) findViewById(R.id.TitleBarLayOut); 

FeaturedButton = new Button(this); 
FeaturedButton.setText("Featured"); 
FeaturedButton.setGravity(Gravity.LEFT); 
int FeaturedButtonWidth = 50; 

playButton = new Button(this); 
playButton.setText("Play"); 
playButton.setGravity(Gravity.RIGHT); 
int playButtonWidth = 50; 

int titleTextWidth = ((screenWidth-playButtonWidth)-FeaturedButtonWidth); 
titleText = new TextView(this); 
titleText.setGravity(Gravity.CENTER); 
titleText.setTextColor(Color.WHITE); 
titleText.setTextSize(14); 
titleText.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD), Typeface.BOLD); 

titlebar.addView(FeaturedButton, new LinearLayout.LayoutParams(
50, LayoutParams.WRAP_CONTENT)); 

titlebar.addView(titleText, new LinearLayout.LayoutParams(
titleTextWidth, LayoutParams.WRAP_CONTENT)); 

titlebar.addView(playButton, new LinearLayout.LayoutParams(
50, LayoutParams.WRAP_CONTENT)); 

CoverArtDisplay = (ImageView) findViewById(R.id.coverArt); 
PlaylistTitleDisplay = (TextView) findViewById(R.id.playlistTitle); 
PlaylistMemberDisplay = (TextView) findViewById(R.id.playlistMember); 
PlaylistDescriptionsDisplay = (TextView) findViewById(R.id.playlistDescriptions); 
+0

我認爲佈局佈局和視圖佈局不合適,這可能會導致這種情況,更好的方法是在xml中指定佈局。通過代碼我們也應該能夠達到預期的效果。 – sat 2011-03-13 18:20:30

+0

我似乎無法設法得到這個排序儘管刪除代碼中的佈局屬性或詮釋他xml,任何意見? – 2011-03-13 18:29:21

回答

2

我碰到你的項目,我認爲你缺少。如果添加它,將顯示帶有文字查看的底部線性佈局。

總之設計不好。將按鈕移動到XML,請重新考慮您的佈局;) 希望它有幫助。

+0

太棒了,你是一個傳奇人物,我知道它不是最漂亮,最好的,但它現在需要爲我工作。謝謝你的幫助 – 2011-03-15 14:33:51

1

很難說這個問題是這麼少的信息是什麼。你是否在Android插件中使用Eclipse?

你是什麼意思「我沒有得到任何顯示」?該應用程序運行,但你只是得到一個空白的看法?

您的活動是否列在AndroidManifest.xml中?在主的LinearLayout

android:orientation="vertical" 

+0

對不起,我使用Eclipse,當它運行我得到的標題欄和兩個按鈕,但在topLayout和bottomLayout沒有顯示,沒有背景顏色或文本。 – 2011-03-13 18:34:10

+0

此外,我的活動在AndroidManifest.xml文件中列出 – 2011-03-13 18:35:06