我试图将我的标签设置为滚动条。我有6个标签,但想在UI中显示3个。如何以此格式设置滚动条视图?如果甚至可以像这样设置它?
Tab Bar基于orroids开发者页面。
由于
<?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">
<ScrollView android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
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" />
</LinearLayout>
</ScrollView>
Java文件
package developers.tab;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;
public class AndroidDevelopersTabActivity extends TabActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable 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, WorkoutActivity.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("workouts").setIndicator("Workout",
res.getDrawable(R.drawable.ic_tab_workout))
.setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, ExcerciseActivity.class);
spec = tabHost.newTabSpec("excercises").setIndicator("Excercises",
res.getDrawable(R.drawable.ic_tab_albums))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, ProgramsActivity.class);
spec = tabHost.newTabSpec("programs").setIndicator("Programs",
res.getDrawable(R.drawable.ic_tab_songs))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, LogActivity.class);
spec = tabHost.newTabSpec("mealplans").setIndicator("Meal Plans",
res.getDrawable(R.drawable.ic_tab_songs))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, BodyMActivity.class);
spec = tabHost.newTabSpec("bodymeasurements").setIndicator("Body Measurements",
res.getDrawable(R.drawable.ic_tab_songs))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, MealPlanActivity.class);
spec = tabHost.newTabSpec("mealplan").setIndicator("Meal Plan",
res.getDrawable(R.drawable.ic_tab_songs))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(2);
}
}
答案 0 :(得分:2)
为什么你不能让不需要的标签“可见”的可见性?
当从一侧滚动到另一侧时,您可以使侧面标签为GONE或VISIBLE。
按view.setVisibility=GONE;
或view.setVisibility=VISIBLE;
如果你观看了GONE,它就不会有任何意义。所有其他视图本身就像viewA不存在一样。听滚动,当有显示右侧标签的位置时,显示它们并隐藏左侧标签。反之亦然。