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>
助けてください!私は何かを見落としてたんだろうが、私は何を把握することはできません:(
私はちょっとレイアウトに2つ必要です... – nubicurio
しかし、何が起こったのか見てみましたか?その理由は、ビューを複数回追加しているためです。 '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
私はインクルードファイルを取り出して、アプリケーションはまったく起動しません(強制終了)。不思議なことに、私はandroid:srcをandroid:backgroundに変更することで問題を解決しているようです。しかし、あなたが作ったのはかなり意味があります...私は実際には2つのみを見ていても実際には4つのタブを持っていますか?私はもう何をしているのかわかりません:( – nubicurio