gpt4 book ai didi

android - 导航类型(固定标签 + 滑动)

转载 作者:行者123 更新时间:2023-11-30 03:37:55 38 4
gpt4 key购买 nike

在我的应用程序中,我有一个带有带有多个选项卡的选项卡小部件的选项卡主机。现在我需要一个选项卡,在选项卡内容中显示一个时间表网格,允许向右和向左滑动以在月份中移动。但我需要该选项卡保持固定,并且只需要滑动日程表。

导航类型(固定标签 + 滑动)允许吗?据我了解,此导航允许滑动,但选项卡不会保持不变。

我需要的是可能的吗?感谢您的帮助和关注。

最佳答案

我想说有可能,请在 tabhost 和 tabwidget 上保留您的代码。

所以我假设其中一个选项卡正在调用一个可能名为 Schedule.class 的 Activity ,默认情况下 tabhost 不允许任何滑动来更改选项卡功能,这很好。

所以在您的计划 Activity 中,您将使用 ViewPager,我从这篇文章中学习了如何使用它:http://thepseudocoder.wordpress.com/2011/10/05/android-page-swiping-using-viewpager/

这很容易理解。你可以尝试使用它,希望我回答了你的问题

更新:这是一个示例

调度类

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.schedule);

ViewPager viewPager = (ViewPager) findViewById(R.id.viewPager);

List<Fragment> fragments = new ArrayList<Fragment>();
fragments.add(Fragment.instantiate(this, Fragment1.class.getName()));
fragments.add(Fragment.instantiate(this, Fragment2.class.getName()));
fragments.add(Fragment.instantiate(this, Fragment3.class.getName()));

MyFragmentAdapter miscFragmentAdapter = new MyFragmentAdapter(getSupportFragmentManager(), fragments);

viewPager.setAdapter(miscFragmentAdapter);
}

MyFragmentAdapter.class

public class MyFragmentAdapter extends FragmentPagerAdapter {

private List<Fragment> fragments;

public MiscFragmentAdapter(FragmentManager fragmentManager, List<Fragment> fragments) {
super(fragmentManager);
this.fragments = fragments;
}

@Override
public Fragment getItem(int position) {
return this.fragments.get(position);
}

@Override
public int getCount() {
return this.fragments.size();
}
}

日程表.xml

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

<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />

</LinearLayout>

Fragment1.class 或 Fragment2.class 或 Fragment3.class

public class Fragment1 extends Fragment {

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
if (container == null) {
// We have different layouts, and in one of them this
// fragment's containing frame doesn't exist. The fragment
// may still be created from its saved state, but there is
// no reason to try to create its view hierarchy because it
// won't be displayed. Note this is not needed -- we could
// just run the code below, where we would create and return
// the view hierarchy; it would just never be used.
return null;
}
return (LinearLayout) inflater.inflate(R.layout.fragment1, container, false);
}
}

fragment1 是一个简单的布局,里面有你想要的任何东西。

关于android - 导航类型(固定标签 + 滑动),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16335874/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com