android - ViewPagerIndicator 的 TitlePageIndicator 阻止 fragment 显示并导致滑动不起作用

标签 android android-fragments android-viewpager

我在尝试使用 ViewPagerIndicator (http://viewpagerindicator.com/) 时看到一个非常奇怪的错误。我已将其缩小到属于该库的 TitlePageIndicator。 当我使用 TitlePageIndicator 时,我无法在选项卡之间滑动,并且我的 fragment 没有显示(尽管它们已创建并运行,但右上角的按钮是由应该显示的 fragment 创建的)。它看起来像这样:http://imgur.com/RJaI9 (对不起,新用户,所以我不能内联图片)

但如果没有,我的 fragment 会正确显示并且我可以在它们之间滑动。 http://imgur.com/bboSd

我不知道为什么会这样。我正在使用最新的 ViewPagerIndicator 库,但我想这可能与我导入它的方式有关?我按照网站上的说明进行操作: 从现有源代码在 eclipse 中创建新的 android 项目,导入兼容性库,然后将其添加到我在 android 项目属性中的项目。

任何帮助将不胜感激,我已经坚持了 2 周 :(

代码:

布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.viewpagerindicator.TitlePageIndicator
    android:id="@+id/titles"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />
<android.support.v4.view.ViewPager
    android:id="@+id/grocery_pager"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
     />
</LinearLayout>

FragmentActivity(来自 ActionBarSherlock):

public class GroceryActivity extends BaseFragmentActivity
{
   @Override
   protected void onCreate(Bundle savedInstanceState)
   {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_grocerylist);
  // Set the pager with an adapter
  ViewPager pager = (ViewPager) findViewById(R.id.grocery_pager);
  pager.setAdapter(new GroceryViewPagerAdapter(getSupportFragmentManager()));

  // Bind the title indicator to the adapter
//When these next two lines are commented out, everything works
  TitlePageIndicator titleIndicator = (TitlePageIndicator) findViewById(R.id.titles);
  titleIndicator.setViewPager(pager);
  }
}

最佳答案

我最终找到了问题:

在我的线性布局中,我没有设置布局的方向。出于一些愚蠢的原因,我认为方向字段与设备的方向有关,而不是布局本身。添加 orientation:vertical 字段使一切正常。

希望这对某人有帮助!

关于android - ViewPagerIndicator 的 TitlePageIndicator 阻止 fragment 显示并导致滑动不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9322988/

相关文章:

android - 如何使用 smack-android 连接到安全禁用的 ejabberd?

java - 如何在 FragmentPagerAdapter 中的 fragment 之间传递数据

android - ViewPager.setCurrentItem 仅适用于将 smoothScroll 设置为 true

android - 如何在 Android 中用新的 Fragment 完全替换 View Pager View

android - 添加解析 UI 小部件但未找到 Gradle DSL 方法 : compile()

java - 在不知道类型的情况下读取文件

android - ViewPager 和 YouTubePlayer

android - viewpager 内的 youtube api [android]

android - HMS Location Kit,仅当用户选择 "Allow all the time"时位置更新才有效

android - 将窗口SystemUiVisibility设置为SYSTEM_UI_FLAG_LIGHT_STATUS_BAR时,全屏DrawerLayouts如何影响将 fragment 添加到后堆栈?