0
저는 Android 개발에 익숙하지 않습니다. 다음과 같은 xml 레이아웃과 코드를 사용하여 TabActivity 안에 탭을 추가 할 수 있지만 선택할 적절한 탭이 표시되지 않습니다. 레이아웃을 몇 번 변경했지만 탭을 표시 할 수 없습니다. TabHost는 하나의 콘텐츠 만 표시합니다.
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="600dp"
android:layout_height="880dp"
android:baselineAligned="false"
android:orientation="vertical" >
<LinearLayout
android:layout_width="600dp"
android:layout_height="840dp"
android:layout_weight="1" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</FrameLayout>
</TabWidget>
</LinearLayout>
<GridLayout
android:layout_width="600dp"
android:layout_height="40dp"
android:layout_weight="1"
android:columnCount="4"
android:rowCount="1" >
<ImageButton
android:id="@+id/button_scan"
style="android:attr/buttonBarButtonStyle"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_row="0"
android:onClick="doScan"
android:src="@drawable/lupa" />
<ImageButton
android:id="@+id/button_foto"
style="android:attr/buttonBarButtonStyle"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="0"
android:src="@drawable/camera" />
<ImageButton
android:id="@+id/button_pinteresses"
style="android:attr/buttonBarButtonStyle"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_column="2"
android:layout_row="0"
android:src="@drawable/globe" />
<ImageButton
android:id="@+id/button_help"
style="android:attr/buttonBarButtonStyle"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_column="3"
android:layout_row="0"
android:src="@drawable/question" />
</GridLayout>
</LinearLayout>
</TabHost>
그리고 TabActivity에서
는 :protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TabHost tabHost;
tabHost = getTabHost();
tabHost.setVisibility(TabHost.VISIBLE);
TabSpec tab1 = tabHost.newTabSpec("TabIndoor");
TabSpec tab2 = tabHost.newTabSpec("TabOutdoor");
tab1.setIndicator("Indoor");
tab1.setContent(new Intent(this, com.paar.ch9.MainActivity.class));
tab2.setIndicator("Outdoor");
tab2.setContent(new Intent(this, com.paar.ch9.MainActivity.class));
tabHost.addTab(tab1);
tabHost.addTab(tab2);
}
어떻게 탭 표시 할 수 있습니까?
Thamk 당신 SMIC, 나는 심지어 내가 GridLayout과의 버튼이 필요합니다, 당신은 표시 변경을 시도했지만 결과는 동일 하나 com.paar.ch9.MainActivity가 표시없이 탭이었다. – ncarneiro
좋아요, 하나 이상의 액티비티를 배치 해 보았습니다. 예를 들어, com.paar.ch9.MainActivity.class의 복제본 대신 one.class 및 two.class 액티비티를 만들고 MainActivity를 사용하여 OnTabChangeListener를 구현하는 TabActivity 만 확장하십시오. 코드가 도움이된다면 도움이 될 것입니다. 코드가 제대로 작동하려면 레이아웃을 가져 오기 위해 사양을 사용자 정의 할 수 있습니다. – Tana
고마워요. 당신이 지적한대로, 레이아웃을 얻었고 그것을 다시 만들었습니다. 이제는 더 효과적입니다. 다시 한 번 감사드립니다. – ncarneiro