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;
    }
}
}
4

1 に答える 1

0

レイアウトが問題の原因です。

を使用する場合はRelativeLayout、内部のウィジェットの移動先を指定する必要がありますRelativeLayout。デフォルトでは、それらはすべて左上隅に配置され、後の子 ( your )は Z 軸ViewPager上で前の子 ( your ) の上に浮かびます。TabPageIndicatorしたがって、現在のレイアウトでは、ユーザーはTabPageIndicator.

に切り替えるかvertical LinearLayout、適切な属性 ( など) を使用して、ウィジェットが重ならないようandroid:layout_belowに整理します。RelativeLayout

Hierarchy View は、この種の問題を特定するのに役立つ便利なツールです。

于 2012-12-24T16:49:46.007 に答える