2011-07-19 252 views
0

我想讓我的佈局,我的第一個標籤是這樣的:的Android XML佈局問題

enter image description here

我已經問類似這樣的問題。我被陷在格式化: 這是我的代碼如下所示:

<?xml version="1.0" encoding="utf-8"?> 
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/tabhost" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
     <LinearLayout 
      android:orientation="vertical"   
      android:layout_width="fill_parent"   
      android:layout_height="fill_parent"   
      android:padding="5dp">   
     <TabWidget 
      android:id="@android:id/tabs"    
      android:layout_width="fill_parent"    
      android:layout_height="wrap_content" />   
     <FrameLayout    
      android:id="@android:id/tabcontent"    
      android:layout_width="fill_parent"    
      android:layout_height="fill_parent"    
      android:padding="5dp" /> 
      <RelativeLayout 
       android:orientation="vertical"     
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" >    
       <ImageView 
        android:id="@+id/simpleMode" 
        android:layout_width="wrap_content"   
        android:layout_height="wrap_content" 
        android:padding = "5dip" 
        android:layout_alignParentLeft="true"   
        android:src="@drawable/ic_tab_artists_grey" /> 
       <TextView  
        android:id="@+id/right_text"   
        android:layout_width="fill_parent"   
        android:layout_height="wrap_content"   
        android:padding="5dip"   
        android:layout_toRightOf="@+id/simpleMode"   
        android:gravity="right"    
        android:text="Description"  />     
      </RelativeLayout>  
     </LinearLayout> 
</TabHost> 

我的項目運行,但絕對沒有任何顯示在屏幕上?非常感謝幫助!

這是我的活動課: package com.joshi.remotedoc;

import android.app.TabActivity; 
import android.os.Bundle; 
import android.widget.TabHost; 
import android.content.Intent; 
import android.content.res.Resources; 

public class Detailed_ModeActivity extends TabActivity { 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState);  
     setContentView(R.layout.patientmode);  
     Resources res = getResources(); 
     // Resource object to get Drawables  
     TabHost tabHost = getTabHost(); 
     // The activity TabHost  
     TabHost.TabSpec spec; 
     // Reusable TabSpec for each tab 
     Intent intent; 
     // Reusable Intent for each tab 
     // Create an Intent to launch an Activity for the tab (to be reused) 
     intent = new Intent().setClass(this, SimpleMode.class); 
     // Initialize a TabSpec for each tab and add it to the TabHost 
     spec = tabHost.newTabSpec("simpleMode").setIndicator("simpleMode", 
       res.getDrawable(R.drawable.ic_tab_artists_white)) 
       .setContent(intent);  
     tabHost.addTab(spec); 
     // Do the same for the other tabs 
     intent = new Intent().setClass(this, DetailedMode.class); 
     spec = tabHost.newTabSpec("2ndtab").setIndicator("MySecondTab",       res.getDrawable(R.drawable.something))      .setContent(intent); 
     // Initialize a TabSpec for each tab and add it to the TabHost 
     spec = tabHost.newTabSpec("detailedMode").setIndicator("detailedMode", 
       res.getDrawable(R.drawable.ic_tab_artists_grey)) 
       .setContent(intent);  
     tabHost.addTab(spec); 
     tabHost.setCurrentTab(2); 
} 

    } 

回答

1

您需要正確定義佈局,然後您需要在開始的活動中加載佈局。

http://developer.android.com/guide/topics/ui/declaring-layout.html

首先您創建XML

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:orientation="vertical" > 
    <TextView android:id="@+id/text" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Hello, I am a TextView" /> 
    <Button android:id="@+id/button" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Hello, I am a Button" /> 
</LinearLayout> 

然後,你需要創建Java來加載XML在OnCreate方法:

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main_layout); 
} 
+0

我已經做到了這一點 – YoKaGe

+0

看在編輯過的版本 – YoKaGe

+0

屏幕是空白的嗎? –