gpt4 book ai didi

android - 在阿拉伯语的 viewpager 中反向滑动

转载 作者:太空狗 更新时间:2023-10-29 14:22:58 26 4
gpt4 key购买 nike

昨天发了一个关于PagerAdapter以及在使用数据库时如何实现的问题。我设法解决了它,但是,我不希望 viewpager 向左滑动/滚动我想要相反的方向(向右滑动)。以下是我的代码:

public class ScrollViewTest6 extends ActionBarAppActivity {

private ViewPager awesomePager;
private static int NUM_AWESOME_VIEWS;
private Context cxt;
private AwesomePagerAdapter awesomeAdapter;
TextView tv;
int _id;
int row_numbers;
int row_position;
private DataAdapter mySQLiteAdapter;
private Cursor cursor;


/** Called when the activity is first created. */
@SuppressWarnings("deprecation")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
cxt = this;

awesomeAdapter = new AwesomePagerAdapter(awesomeAdapter);
awesomePager = (ViewPager) findViewById(R.id.awesomepager);
awesomePager.setAdapter(awesomeAdapter);

mySQLiteAdapter = new DataAdapter(this);
mySQLiteAdapter.createDatabase();
mySQLiteAdapter.open();

Bundle extras = getIntent().getExtras();
if (extras == null) {
return;
}

_id = extras.getInt("id");
row_numbers = extras.getInt("row_num");
row_position = extras.getInt("row_pos");


NUM_AWESOME_VIEWS = row_numbers;

awesomePager.setCurrentItem(row_position);

cursor = mySQLiteAdapter.get_AllColumns();
this.startManagingCursor(cursor);


this.awesomePager.setOnPageChangeListener(new ViewPager.OnPageChangeListener()
{
@Override
public void onPageScrollStateChanged(int arg0) {
}

@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels){
}

@Override
public void onPageSelected(int position){
}

});
}

private class AwesomePagerAdapter extends PagerAdapter{

public AwesomePagerAdapter(PagerAdapter fm) {
}


@Override
public int getCount() {
return NUM_AWESOME_VIEWS;
}



@Override
public int getItemPosition(Object object) {return POSITION_NONE;}
@Override
public Object instantiateItem(ViewGroup collection, int position) {

LayoutInflater inflater = (LayoutInflater)cxt.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.mylayout, null);
TextView Title = (TextView)layout.findViewById(R.id.title);


if (cursor != null ) {
if (cursor.moveToPosition(position)) {
//do {
//cursor.moveToPosition(position);
String text = cursor.getString(
cursor.getColumnIndexOrThrow(DataAdapter.KEY_Title));

Title.setText(text);
}
}

((ViewPager) collection).addView(layout,0);
return layout;
}


@Override
public void destroyItem(View collection, int position, Object view) {
((ViewPager) collection).removeView((View) view);
}

@Override
public boolean isViewFromObject(View view, Object object) {
return view==((View)object);
}

@Override
public void finishUpdate(View arg0) {
}


@Override
public void restoreState(Parcelable arg0, ClassLoader arg1) {
}

@Override
public Parcelable saveState() {
return null;
}

@Override
public void startUpdate(View arg0) {
}

}
}

我知道有些人建议使用设置当前项目(整数);//最后一页

但这与 ListView 顺序冲突。

例如 ListView :

1

2

3

当我们使用上面的行时,它显示 1 <- 2 <- 3(从 3 开始)

我想要 3 <- 2 <- 1(从 1 开始)

最佳答案

我遇到了这个问题,我用这个库解决了使用它,您的分页将从右到左完美工作它和 ViewPager 一样工作

https://github.com/diego-gomez-olvera/RtlViewPager

 <com.booking.rtlviewpager.RtlViewPager
android:id="@+id/arabicViewPager"
android:layout_width="match_parent"
android:layout_height="match_parent" />

arabicViewPager = (ViewPager) findViewById(R.id.arabicViewPager);
adapterViewPager = new Adpt_fragmentPageAdapter(getSupportFragmentManager());
arabicViewPager.setAdapter(adapterViewPager);

tabLayout = (TabLayout) findViewById(R.id.sliding_tabs);
tabLayout.setupWithViewPager(arabicViewPager);

关于android - 在阿拉伯语的 viewpager 中反向滑动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15109636/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com