晚安,我是新手,认为我需要做的就是使用一个隐藏标题和标题的滚动效果。显示以下内容。例如:当您花费A和B时,联系人列表中会发生什么,但仍保留所有联系人信函。
我在ios中使用ViewForHeaderInSection实现了一个示例,这是他们用来在Instagram中执行此操作的功能,这是我在android中需要做的事情。
这是我发现的最接近的事情:
访问How to implement a scroll view on only part of my layout
谢谢,我为我的英语道歉并不好。
答案 0 :(得分:0)
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import java.util.ArrayList;
import java.util.List;
import mijem.bitgray.us.mijem_android.R;
public class FragmentTutorial extends Fragment {
/**
* The number of pages (wizard steps) to show in this demo.
*/
private static final int NUM_PAGES = 3;
/**
* The pager widget, which handles animation and allows swiping horizontally
* to access previous and next wizard steps.
*/
private ViewPager mPager;
/**
* The pager adapter, which provides the pages to the view pager widget.
*/
private PagerAdapter mPagerAdapter;
ImageView indicator0;
ImageView indicator1;
ImageView indicator2;
List<ImageView> listIndicators = new ArrayList<ImageView>();
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
ViewGroup rootView = (ViewGroup) inflater.inflate(
R.layout.fragment_viewpager_tutorial, container, false);
// Instantiate a ViewPager and a PagerAdapter.
mPager = (ViewPager) rootView.findViewById(R.id.pager);
mPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageSelected(int position) {
resetIndicators();
listIndicators.get(mPager.getCurrentItem()).setImageResource(
R.drawable.indicador_slide_on);
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
// TODO Auto-generated method stub
}
@Override
public void onPageScrollStateChanged(int arg0) {
// TODO Auto-generated method stub
}
});
mPagerAdapter = new ScreenSlidePagerAdapter(getActivity()
.getSupportFragmentManager());
mPager.setAdapter(mPagerAdapter);
indicator0 = (ImageView) rootView.findViewById(R.id.indicator0);
indicator1 = (ImageView) rootView.findViewById(R.id.indicator1);
indicator2 = (ImageView) rootView.findViewById(R.id.indicator2);
listIndicators.add(indicator0);
listIndicators.add(indicator1);
listIndicators.add(indicator2);
return rootView;
}
@Override
public void onResume() {
// TODO Auto-generated method stub
super.onResume();
//TabListener.onResumeFragment(this);
}
public void resetIndicators() {
for (ImageView img : listIndicators)
img.setImageResource(R.drawable.indicador_slide_off);
}
/**
* A simple pager adapter that represents 5 ScreenSlidePageFragment objects,
* in sequence.
*/
private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
public ScreenSlidePagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
ScreenSlidePageFragment fragment = new ScreenSlidePageFragment();
fragment.setPosition(position);
return fragment;
}
@Override
public int getCount() {
return NUM_PAGES;
}
}
}
enter code here
和适配器:
private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
public ScreenSlidePagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
ScreenSlidePageFragment fragment = new ScreenSlidePageFragment();
fragment.setPosition(position);
return fragment;
}
@Override
public int getCount() {
return NUM_PAGES;
}
}
enter code here
fragmen模式代码
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import java.util.ArrayList;
import java.util.List;
import mijem.bitgray.us.mijem_android.R;
public class FragmentTutorial extends Fragment {
/**
* The number of pages (wizard steps) to show in this demo.
*/
private static final int NUM_PAGES = 3;
/**
* The pager widget, which handles animation and allows swiping horizontally
* to access previous and next wizard steps.
*/
private ViewPager mPager;
/**
* The pager adapter, which provides the pages to the view pager widget.
*/
private PagerAdapter mPagerAdapter;
ImageView indicator0;
ImageView indicator1;
ImageView indicator2;
List<ImageView> listIndicators = new ArrayList<ImageView>();
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
ViewGroup rootView = (ViewGroup) inflater.inflate(
R.layout.fragment_viewpager_tutorial, container, false);
// Instantiate a ViewPager and a PagerAdapter.
mPager = (ViewPager) rootView.findViewById(R.id.pager);
mPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageSelected(int position) {
resetIndicators();
listIndicators.get(mPager.getCurrentItem()).setImageResource(
R.drawable.indicador_slide_on);
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
// TODO Auto-generated method stub
}
@Override
public void onPageScrollStateChanged(int arg0) {
// TODO Auto-generated method stub
}
});
mPagerAdapter = new ScreenSlidePagerAdapter(getActivity()
.getSupportFragmentManager());
mPager.setAdapter(mPagerAdapter);
indicator0 = (ImageView) rootView.findViewById(R.id.indicator0);
indicator1 = (ImageView) rootView.findViewById(R.id.indicator1);
indicator2 = (ImageView) rootView.findViewById(R.id.indicator2);
listIndicators.add(indicator0);
listIndicators.add(indicator1);
listIndicators.add(indicator2);
return rootView;
}
@Override
public void onResume() {
// TODO Auto-generated method stub
super.onResume();
//TabListener.onResumeFragment(this);
}
public void resetIndicators() {
for (ImageView img : listIndicators)
img.setImageResource(R.drawable.indicador_slide_off);
}
/**
* A simple pager adapter that represents 5 ScreenSlidePageFragment objects,
* in sequence.
*/
private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
public ScreenSlidePagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
ScreenSlidePageFragment fragment = new ScreenSlidePageFragment();
fragment.setPosition(position);
return fragment;
}
@Override
public int getCount() {
return NUM_PAGES;
}
}
}