android 简单的点击图片放大展示



import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.annotation.Nullable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;


import com.bumptech.glide.Glide;


import java.util.ArrayList;


import butterknife.BindView;
import butterknife.ButterKnife;
import soule.zjc.com.client_android_soule.R;
import soule.zjc.com.client_android_soule.core.base.BaseActivity;
import soule.zjc.com.client_android_soule.ui.fragment.SouQuanFragment2;


public class ImageLookActivity extends Activity {
    ArrayList<String> images = new ArrayList<>();
    ViewPager viewpager1;
    TextView number;
    int pos;
    ImageView imv_back;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_image_look);


        getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        viewpager1 = findViewById(R.id.viewpager1);
        number = findViewById(R.id.number);
        SouQuanFragment2.isPush =false ;
        imv_back = findViewById(R.id.imv_back);
        imv_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        initOther();
    }


    public void initOther() {
        images = (ArrayList<String>) getIntent().getSerializableExtra("images");
        pos = getIntent().getIntExtra("pos",-1);
        number.setText(pos+1+"/"+images.size());
        viewpager1.setAdapter(adapter);
        viewpager1.setCurrentItem(pos);
        viewpager1.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) {
                pos=position;
                number.setText(pos+1+"/"+images.size());
            }
        });
    }
//    protected int getLayoutId() {
//        return R.layout.activity_image_look;
//    }
    //-----初始化PagerAdapter------


    PagerAdapter adapter=new PagerAdapter(){
        @Override
        public int getCount() {
            return images.size();
        }
        @Override
        public boolean isViewFromObject(View arg0, Object arg1) {
            return arg0==arg1;
        }
        @Override
        public void destroyItem(ViewGroup container, int position, Object o){
        }
        @Override
        public Object instantiateItem(ViewGroup container,int position){
            ImageView im=new ImageView(ImageLookActivity.this);
            Glide.with(ImageLookActivity.this).load(images.get(position)).into(im);
            container.addView(im);
            return im;
        }
    };

}


<?xml version="1.0" encoding="utf-8"?>
<FrameLayout  xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="soule.zjc.com.client_android_soule.ui.activity.ImageLookActivity">
    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager1"
        android:background="@color/colorTextColor0"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >


    </android.support.v4.view.ViewPager>




    <TextView
        android:id="@+id/number"
        android:textSize="@dimen/text_size_18"
        android:text="1/5"
        android:gravity="center_horizontal"
        android:layout_gravity="bottom"
        android:layout_marginBottom="30dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="@color/white"


        />




</FrameLayout>

//在adapter进行跳转

  Intent intent = new Intent(context, ImageLookActivity.class);
                       intent.putExtra("images",(Serializable)images);
                       intent.putExtra("pos",i);
                       context.startActivity(intent);

发布了59 篇原创文章 · 获赞 11 · 访问量 3万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览