Я хочу сделать приложение для Android, которое имеет два крана в одном представлении, т. Е. Имеет верхнюю вкладку и нижнюю вкладку.Как реализовать двойную вкладку в Android?
В соответствии с выбором нижней вкладки я добавляю новый узел вкладки (для верхней вкладки) в части tapcontent нижней вкладки. Но верхний кран не поднимается, он придерживается нижней вкладки.
Реализация верхней вкладки есть,
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
public class uppertab extends TabActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.upperlayout);
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
intent = new Intent().setClass(this, recommend_friend_simillar.class);
spec = tabHost.newTabSpec("upper1").setIndicator("Upper1").setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, recommend_friend_new.class);
spec = tabHost.newTabSpec("upper2").setIndicator("Upper2").setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, recommend_friend_favorite.class);
spec = tabHost.newTabSpec("upper3").setIndicator("Upper3").setContent(intent);
tabHost.addTab(spec);
}
}
XML для верхнего крана,
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/uppertabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TabWidget
android:id="@+id/uppertabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@+id/uppertabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
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"
>
<TabHost android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget android:id="@android:id/tabs"
android:layout_alignParentBottom="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<FrameLayout android:id="@android:id/tabcontent"
android:layout_above="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</FrameLayout>
</RelativeLayout>
</TabHost>
</LinearLayout>
Результат показан ниже.
□□□□□□□□□□□□□□□□□□□□□□□□□□
□ □
□ □
□ □
□ □
□ □
□□□□□□□□□□□□□□□□□□□□□□□□□□
□ □ □ □
□upper1 □ upper2 □ upper3□
□□□□□□□□□□□□□□□□□□□□□□□□□□
□ lower1□lower2 □ lower3□
□□□□□□□□□□□□□□□□□□□□□□□□□□
Конечно, верхние 3 краны должны придерживаться Ceilling, как,
□□□□□□□□□□□□□□□□□□□□□□□□□□
□ □ □ □
□upper1 □ upper2 □ upper3□
□□□□□□□□□□□□□□□□□□□□□□□□□□
□ □
□ □
□ □
□ □
□ □
□□□□□□□□□□□□□□□□□□□□□□□□□□
□ lower1□ lower2 □ lower3□
□□□□□□□□□□□□□□□□□□□□□□□□□□
(я получил совет, который с помощью activitygroup, но он не работает.)
import android.app.ActivityGroup;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
public class uppertab extends ActivityGroup {
private TabHost tabHost;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.upperlay);
tabHost = (TabHost)findViewById(R.id.friendtabhost);
tabHost.setup(getLocalActivityManager());
tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("tab1").setContent(new Intent(this, tab1.class)));
tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("tab2").setContent(new Intent(this, tab2.class)));
tabHost.addTab(tabHost.newTabSpec("tab3").setIndicator("tab3").setContent(new Intent(this, tab3.class)));
}
}
DDMS сообщает, что
tabHost.setup (getLocalActivityManager());
есть проблема. ?.
Что я могу сделать :(
Возможно, вы захотите назвать свой вопрос «Как реализовать ** вложенную ** TabActivity в android?». (Обратите внимание также на правописание «TabActivity».) – user634618