在viewpagerIndicator中自定义SampleIconsDefault

时间:2013-11-13 13:25:03

标签: android android-layout android-viewpager viewpagerindicator

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

  1. 自定义com.viewpagerindicator.IconPageIndicator - 放置一些空间等。
  2. 获取onclick中每个图标的com.viewpagerindicator.IconPageIndicator功能 - 目前只有滑动可用。如果我点击图标,则没有任何反应。
  3. 这是代码: 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);
        }
    }
    

    sample_icon.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。 我正处于一个血腥的截止日期。任何帮助都非常感谢。

1 个答案:

答案 0 :(得分: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();
}

}