0

我在 viewpagerIndicator 中实现 SampleIconsDefault。我需要两件事。

  1. 自定义com.viewpagerindicator.IconPageIndicator- 放置一些空间等。
  2. 获取onclick每个图标的功能com.viewpagerindicator.IconPageIndicator- 目前只有滑动可用。如果我点击图标,什么也不会发生。`

这是代码:SampleIconsDefault.java

package com.viewpagerindicator.sample;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import com.viewpagerindicator.IconPageIndicator;

public class SampleIconsDefault extends BaseSampleActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.simple_icons);

        mAdapter = new TestFragmentAdapter(getSupportFragmentManager());

        mPager = (ViewPager)findViewById(R.id.pager);
        mPager.setAdapter(mAdapter);

        mIndicator = (IconPageIndicator)findViewById(R.id.indicator);
        mIndicator.setViewPager(mPager);
    }
}

示例图标.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:gravity="center_horizontal|center_vertical"
    android:layout_gravity="center_horizontal|center_vertical">


    <com.viewpagerindicator.IconPageIndicator
        android:id="@+id/indicator"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:paddingTop="0dp"
        android:paddingBottom="0dp"
        android:layout_margin="0dp"
        android:background="#464646"
        android:layout_gravity="center_vertical|fill_horizontal"

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

</LinearLayout>

我看不出定制的方法com.viewpagerindicator.IconPageIndicator。我正处于一个该死的最后期限。非常感谢任何帮助。

4

1 回答 1

0

请参阅此代码,您必须完全按照此处完成的操作。

public class SampleTitlesCenterClickListener extends BaseSampleActivity implements OnCenterItemClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.simple_titles);

    mAdapter = new TestFragmentAdapter(getSupportFragmentManager());

    mPager = (ViewPager)findViewById(R.id.pager);
    mPager.setAdapter(mAdapter);

    TitlePageIndicator indicator = (TitlePageIndicator)findViewById(R.id.indicator);
    indicator.setViewPager(mPager);
    indicator.setFooterIndicatorStyle(IndicatorStyle.Underline);
    indicator.setOnCenterItemClickListener(this);
    mIndicator = indicator;
}

@Override
public void onCenterItemClick(int position) {
    Toast.makeText(this, "You clicked the center title!", Toast.LENGTH_SHORT).show();
}

}

于 2013-11-13T13:48:24.343 回答