2011-11-14 17 views
0

2つのタブ付きアクティビティを持つアプリケーションを作成しようとしています。ここでは、tab1に画像とその上にテキストがあり、tab2ユーザーがクリックすることができる2つのボタンがあります(それはさらなる活動につながるはずです)Androidタブ:2番目のタブのコンテンツが最初のタブのコンテンツの下に隠される

何らかの理由で、私はtab2のボタンを表示できませんでした。私が見ることができるのは、tab1からの同じ画像です。詳しく調べると、タブ1の画像の下にボタンが隠れていることがわかりました。私は間違って何をしていますか?どのようにしてその写真を消して、tab2に現れないようにするのですか?

次は私のコードです:

IndexActivity

public class IndexActivity extends TabActivity { 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    TabHost.TabSpec spec = getTabHost().newTabSpec("tab1"); 
    spec.setContent(R.id.tab1content); 
    spec.setIndicator("tab1"); 
    getTabHost().addTab(spec); 

    spec = getTabHost().newTabSpec("tab2"); 
    spec.setContent(R.id.tab2content); 
    spec.setIndicator("tab2"); 
    getTabHost().addTab(spec); 

    getTabHost().setCurrentTab(0);  

    } 
} 

マイmain.xmlファイルはこのように書き:

<?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">  
       <include layout="@layout/tab1"/> 
       <include layout="@layout/tab2"/>    
      </FrameLayout>   
</LinearLayout> 

tab1.xmlは、このようなものです:

<?xml version="1.0" encoding="utf-8"?> 
<merge xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent"> 
     <ImageView android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:scaleType="center" 
        android:src="@drawable/pic"/> 
     <ScrollView android:id="@+id/scrolltab1" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"> 
     <TextView android:id="@+id/tab1content" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
        android:background="#65000000" 
        android:text="@string/text" 
      android:textColor="#ffffffff" 
      android:textSize="20sp" 
       android:padding="15dp" 
     /> 
     </ScrollView>  
</merge> 

TAB2は、このようなものです:

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

    <Button 
     android:id="@+id/button2" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1.10" 
     android:text="Button" /> 

    <Button 
     android:id="@+id/button1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1.10" 
     android:text="Button" /> 

</LinearLayout> 

助けてください!私は何かを見落としてたんだろうが、私は何を把握することはできません:(

答えて

0

あなたmain.xmlFrameLayoutから次の2行を削除し、何が起こるかを参照してください。

<include layout="@layout/tab1"/> 
<include layout="@layout/tab2"/>    
+0

私はちょっとレイアウトに2つ必要です... – nubicurio

+0

しかし、何が起こったのか見てみましたか?その理由は、ビューを複数回追加しているためです。 'setContentView(R.layout.main) 'を呼び出すと、' tab1.xml'と 'tab2.xml'のレイアウトが自動的に追加されますが、最初に' TextView'(tab1content)を含む 'TabSpecs'を作成しています)は 'tab1.xml'から、第2は' tab2.xml'(tab2content)からレイアウト全体を含んでいます。 'spec.setContent(...)'を呼び出すと、 'setContentView(R.layout.main)'が 'main.xml'内の要素のために既に行ったレイアウトファイルの内容を手動で繰り返しています。 – Squonk

+0

私はインクルードファイルを取り出して、アプリケーションはまったく起動しません(強制終了)。不思議なことに、私はandroid:srcをandroid:backgroundに変更することで問題を解決しているようです。しかし、あなたが作ったのはかなり意味があります...私は実際には2つのみを見ていても実際には4つのタブを持っていますか?私はもう何をしているのかわかりません:( – nubicurio

0

私はあなたがこれを見てsugggest ....

あなたは、たとえば、実際にかなりandroid tabhost tutorial

....この例を表しています

私はこれは私が延期私の最初のAndroidタブウィジェットを開発するときに使用される1 ...

PSだった....あなたはすでにそれを見ている願っています。この例上記のpart 2を見ています。..あなたが知る必要のあるもの全てを継続してください。

+0

ありがとうございます!私は朝のこの最初の事を見ていきます... – nubicurio

+0

それはあなたの問題を解決しましたか...もしあなたがあなたの問題への答えとして私の答えを示すのに気をつけてもらえますか?あなたが試したことを教えてください。 – medampudi

0

はあなたのコードとXMLを見て、私はこの問題は、この行とtab1.xmlであると思う:

<TextView android:id="@+id/tab1content"... 

ImageViewScrollView周りのレイアウトを置くようにしてください。 android:id="@+id/tab1content"をレイアウトに移動します。このような何か:

<?xml version="1.0" encoding="utf-8"?> 
<merge xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 
    <LinearLayout android:id="@+id/tab1content" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 

     <ImageView android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:scaleType="center" 
       android:src="@drawable/pic"/> 
     <ScrollView android:id="@+id/scrolltab1" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent"> 
     <TextView android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:background="#65000000" 
      android:text="@string/text" 
      android:textColor="#ffffffff" 
      android:textSize="20sp" 
      android:padding="15dp" /> 
     </ScrollView> 

    </LinearLayout> 
</merge> 
+0

ちょっとボタンがtab2に現れます。しかし、tab1のテキスト "@文字列/テキスト"は表示されなくなりました。( – nubicurio

+0

あなたのレイアウトに別の問題があります。このスレッドで答えをマークし、新しい問題について新しい質問をしてください。 – C0deAttack

+0

何か他のものもありますが、アンドロイド:srcをアンドロイドに変更して問題を解決しました... – nubicurio

関連する問題