1. <tfoot id='f5eys'></tfoot>
    • <bdo id='f5eys'></bdo><ul id='f5eys'></ul>

  2. <legend id='f5eys'><style id='f5eys'><dir id='f5eys'><q id='f5eys'></q></dir></style></legend>

    <small id='f5eys'></small><noframes id='f5eys'>

    <i id='f5eys'><tr id='f5eys'><dt id='f5eys'><q id='f5eys'><span id='f5eys'><b id='f5eys'><form id='f5eys'><ins id='f5eys'></ins><ul id='f5eys'></ul><sub id='f5eys'></sub></form><legend id='f5eys'></legend><bdo id='f5eys'><pre id='f5eys'><center id='f5eys'></center></pre></bdo></b><th id='f5eys'></th></span></q></dt></tr></i><div id='f5eys'><tfoot id='f5eys'></tfoot><dl id='f5eys'><fieldset id='f5eys'></fieldset></dl></div>

    1. Android viewPager 图片从右向左滑动

      Android viewPager image slide right to left(Android viewPager 图片从右向左滑动)

            <tfoot id='WC74j'></tfoot>
              <tbody id='WC74j'></tbody>

              <i id='WC74j'><tr id='WC74j'><dt id='WC74j'><q id='WC74j'><span id='WC74j'><b id='WC74j'><form id='WC74j'><ins id='WC74j'></ins><ul id='WC74j'></ul><sub id='WC74j'></sub></form><legend id='WC74j'></legend><bdo id='WC74j'><pre id='WC74j'><center id='WC74j'></center></pre></bdo></b><th id='WC74j'></th></span></q></dt></tr></i><div id='WC74j'><tfoot id='WC74j'></tfoot><dl id='WC74j'><fieldset id='WC74j'></fieldset></dl></div>

              <legend id='WC74j'><style id='WC74j'><dir id='WC74j'><q id='WC74j'></q></dir></style></legend>
              • <bdo id='WC74j'></bdo><ul id='WC74j'></ul>
              • <small id='WC74j'></small><noframes id='WC74j'>

                本文介绍了Android viewPager 图片从右向左滑动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我想添加一张图片幻灯片.但不能让它从右向左滑动.(适用于阿拉伯语或希伯来语等语言)

                I want to add an image slide. But cannot make it slide from right to left. (for languages like Arabic or Hebrew)

                我几乎检查了stackoverflow中的所有回复,但找不到明确的解决方案.

                I checked nearly all replies in stackoverflow, but can not find a clear solution.

                我在这里写下整个代码.

                I write here the whole code.

                请写清楚,我不是专业人士

                主活动;

                package com.manishkpr.viewpagerimagegallery;
                
                import android.app.Activity;
                import android.os.Bundle;
                import android.support.v4.view.ViewPager;
                
                public class MainActivity extends Activity {
                  @Override
                  public void onCreate(Bundle savedInstanceState) {
                    super.onCreate(savedInstanceState);
                    setContentView(R.layout.activity_main);
                
                    ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
                    ImageAdapter adapter = new ImageAdapter(this);
                    viewPager.setAdapter(adapter);
                
                
                  }
                
                
                }
                

                这里是这ImageAdapter.java;

                here is the ImageAdapter.java;

                package com.manishkpr.viewpagerimagegallery;
                
                import android.content.Context;
                import android.support.v4.view.PagerAdapter;
                import android.support.v4.view.ViewPager;
                import android.view.View;
                import android.view.ViewGroup;
                import android.widget.ImageView;
                
                public class ImageAdapter extends PagerAdapter {
                    Context context;
                    private int[] GalImages = new int[] {
                        R.drawable.one,
                        R.drawable.two,
                        R.drawable.three
                    };
                    ImageAdapter(Context context){
                        this.context=context;
                    }
                    @Override
                    public int getCount() {
                      return GalImages.length;
                    }
                
                    @Override
                    public boolean isViewFromObject(View view, Object object) {
                      return view == ((ImageView) object);
                    }
                
                    @Override
                    public Object instantiateItem(ViewGroup container, int position) {
                      ImageView imageView = new ImageView(context);
                      int padding = context.getResources().getDimensionPixelSize(R.dimen.padding_medium);
                      imageView.setPadding(padding, padding, padding, padding);
                      imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
                      imageView.setImageResource(GalImages[position]);
                      ((ViewPager) container).addView(imageView, 0);
                
                
                      return imageView;
                    }
                
                    @Override
                    public void destroyItem(ViewGroup container, int position, Object object) {
                      ((ViewPager) container).removeView((ImageView) object);
                    }
                  }
                

                这是布局文件;

                <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" >
                
                          <android.support.v4.view.ViewPager
                          android:id="@+id/view_pager"
                          android:layout_width="match_parent"
                          android:layout_height="match_parent" />
                
                </RelativeLayout>
                

                推荐答案

                创建一个布局文件pager_item.xml:

                <?xml version="1.0" encoding="utf-8"?>
                
                <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:orientation="vertical" android:layout_width="match_parent"
                android:layout_height="match_parent">
                
                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:id="@+id/imageView" />
                </LinearLayout>
                

                像这样更改您的 PagerAdapter:

                Change your PagerAdapter like this:

                public class ImageAdapter extends PagerAdapter {
                Context context;
                private int[] GalImages = new int[] {
                    R.drawable.one,
                    R.drawable.two,
                    R.drawable.three
                };
                
                LayoutInflater mLayoutInflater;
                
                ImageAdapter(Context context){
                    this.context=context;
                    mLayoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                }
                @Override
                public int getCount() {
                  return GalImages.length;
                }
                
                @Override
                public boolean isViewFromObject(View view, Object object) {
                  return view == ((LinearLayout) object);
                }
                
                @Override
                public Object instantiateItem(ViewGroup container, int position) {
                    View itemView = mLayoutInflater.inflate(R.layout.pager_item, container, false);
                
                    ImageView imageView = (ImageView) itemView.findViewById(R.id.imageView);
                    imageView.setImageResource(GalImages[position]);
                
                    container.addView(itemView);
                
                    return itemView;
                }
                
                @Override
                public void destroyItem(ViewGroup container, int position, Object object) {
                  container.removeView((LinearLayout)object);
                }
                }
                

                编辑 1:

                一招:

                public class MainActivity extends Activity {
                
                
                @Override
                  public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_main);
                
                ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
                ImageAdapter adapter = new ImageAdapter(this);
                viewPager.setAdapter(adapter);
                viewPager.setCurrentItem(adapter.getCount()-1);
                
                }
                

                我希望这会有所帮助:)

                I hope this helps :)

                这篇关于Android viewPager 图片从右向左滑动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                How can I use CClistview in COCOS2d Android?(如何在 COCOS2d Android 中使用 CClistview?)
                cocos2d-android: how to display score(cocos2d-android:如何显示分数)
                Sqlite database not copied from asset folder Android(Sqlite 数据库未从资产文件夹 Android 复制)
                SQLite Database Copy Appears Corrupted When Generated by Device and not Emulator(SQLite 数据库副本在由设备而不是模拟器生成时出现损坏)
                Android file copy(安卓文件拷贝)
                Android how to detect Copy event of Edittext in android(Android如何在android中检测Edittext的Copy事件)

                      <tbody id='6sduK'></tbody>

                        <bdo id='6sduK'></bdo><ul id='6sduK'></ul>

                        <small id='6sduK'></small><noframes id='6sduK'>

                          <legend id='6sduK'><style id='6sduK'><dir id='6sduK'><q id='6sduK'></q></dir></style></legend>
                        • <tfoot id='6sduK'></tfoot>
                        • <i id='6sduK'><tr id='6sduK'><dt id='6sduK'><q id='6sduK'><span id='6sduK'><b id='6sduK'><form id='6sduK'><ins id='6sduK'></ins><ul id='6sduK'></ul><sub id='6sduK'></sub></form><legend id='6sduK'></legend><bdo id='6sduK'><pre id='6sduK'><center id='6sduK'></center></pre></bdo></b><th id='6sduK'></th></span></q></dt></tr></i><div id='6sduK'><tfoot id='6sduK'></tfoot><dl id='6sduK'><fieldset id='6sduK'></fieldset></dl></div>