我的图片滑块不适用于所有设备

时间:2017-07-29 03:08:38

标签: java android image

我创建了一个包含多个按钮的应用程序,每个按钮都连接了多个照片(图像滑块(我想我正在使用查看器页面使用图像滑块)).......它在某些设备上运行良好例如6.0.1但是当我想在4.2.2等其他设备上使用它时,一旦我点击了butuon就会立即停止,这里我已经完成了xml(它的名字是tip_3)

<android.support.v4.view.ViewPager
    android:id="@+id/viewPager"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
</android.support.v4.view.ViewPager>

我创建了另一个xml(作为youtube中的演练)(xml名称algwhra)

<ImageView
    android:id="@+id/imageView2"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

这里是java for(tips_3):

import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class Tips_3 extends AppCompatActivity {

    ViewPager viewPager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tips_3);

        viewPager = (ViewPager) findViewById(R.id.viewPager);

        AlGwhra viewPagerAdapter = new AlGwhra(this);

        viewPager.setAdapter(viewPagerAdapter);



    }
}

这是(algwhra)java:

import android.content.Context;
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 javax.xml.transform.Result;


/**
 * Created by Hassan on 12-Jul-17.
 */

public class AlGwhra extends PagerAdapter{

    private Context context;
    private LayoutInflater layoutInflater;
    private Integer[] images ={R.drawable.g1,R.drawable.g2,R.drawable.g3,R.drawable.g4,R.drawable.g5,R.drawable.g6,R.drawable.g7,R.drawable.g8,R.drawable.g9,R.drawable.g10,R.drawable.g11,R.drawable.g12,R.drawable.g13};

    public AlGwhra(Context context) {
        this.context = context;
    }

    @Override
    public int getCount() {
        return images.length;
    }

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

    @Override
    public Object instantiateItem(ViewGroup container, int position) {

        layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = layoutInflater.inflate(R.layout.algwhra, null);
        ImageView imageView =(ImageView) view.findViewById(R.id.imageView2);
        imageView.setImageResource(images[position]);

        ViewPager vp =(ViewPager) container;
        vp.addView(view ,0);
        return view;

     }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {

        ViewPager vp =(ViewPager) container;
        View view =(View) object;
        vp.removeView(view);


    }

}

0 个答案:

没有答案