0

i have created a new project and included the HoloEveryWhere library. Then I decided to add the ViewPageIndicator. I copied all the code from ViewPageIndicator sample but it didn't work. I tried using SherlockFragment but that didn't work either. So I removed HoloEveryWhere from my project but apparently that wasn't the problem cause it still doesn't swipe.

edit:

this is my xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >

<com.viewpagerindicator.TabPageIndicator
    android:id="@+id/indicator"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    />
<android.support.v4.view.ViewPager
    android:id="@+id/pager"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    />

you see, i just copied the two tags from the samples. this is the main.java:

package com.example.test;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import com.viewpagerindicator.TabPageIndicator;

public class MainActivity extends FragmentActivity {
private static final String[] CONTENT = new String[] { "Recent", "Artists", "Albums", "Songs", "Playlists", "Genres" };

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

    FragmentPagerAdapter adapter = new GoogleMusicAdapter(getSupportFragmentManager());

    ViewPager pager = (ViewPager)findViewById(R.id.pager);
    pager.setAdapter(adapter);

    TabPageIndicator indicator = (TabPageIndicator)findViewById(R.id.indicator);
    indicator.setViewPager(pager);
}

class GoogleMusicAdapter extends FragmentPagerAdapter {
    public GoogleMusicAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int position) {
        return TestFragment.newInstance(CONTENT[position % CONTENT.length]);
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return CONTENT[position % CONTENT.length];
    }

    @Override
    public int getCount() {
      return CONTENT.length;
    }
}
}

1 Answers1

0

Your layout is the source of your difficulty.

If you are going to use RelativeLayout, you need to specify where the widgets inside the RelativeLayout go. By default, they all go in the upper-left corner, and later children (your ViewPager) float over top of earlier children (your TabPageIndicator) on the Z axis. Hence, with your current layout, the user cannot touch your TabPageIndicator.

Either switch to a vertical LinearLayout or use the appropriate attributes (e.g., android:layout_below) to organize your widgets in the RelativeLayout so that they do not overlap.

Hierarchy View is a useful tool for helping you identify this sort of problem.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491