android GridView 选中后 图片变大 图片放大不会被遮住



package com.video.browse;

import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import com.video.browse.adapter.VideoAdapter;
import com.video.browse.ui.VideoGridView;
import com.video.browse.util.Constant;
import com.video.browse.util.FileFind;
import com.video.browse.util.FileVoideInfo;
import com.video.browse.util.MediaFormat;

import android.R.bool;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.app.Activity;

public class MainActivity extends Activity {
	private static final String TAG = "MainActivity";
	List<FileVoideInfo> list = new ArrayList<FileVoideInfo>();
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		if (FileFind.isFileName(Constant.MOVIE_PATH_SD)) {
			File filePath = new File(Constant.FILE_PATH);
			list = FileFind.getFileList(filePath, true);
			Log.i(TAG, "list size:"+list.size());
		}
		
		final VideoGridView gridview = (VideoGridView) findViewById(R.id.gridview);
		VideoAdapter mImageAdapter = new VideoAdapter(this,list);
		gridview.setAdapter(mImageAdapter);
		gridview.setOnItemClickListener(new OnItemClickListener() {
			
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				Toast.makeText(MainActivity.this, "" + position,Toast.LENGTH_SHORT).show();// 显示信息;
				 
			}
			
		});
		gridview.setOnItemSelectedListener(new OnItemSelectedListener() {  
		    public void onItemSelected(AdapterView<?> arg0, View arg1,  
		    	    int arg2, long arg3) {  
		    	    Log.d("zonesView", "onItemSelected");
		    	    gridview.setCurrentPosition(arg2);
		    	    VideoAdapter zonesImageAdapter = (VideoAdapter) gridview.getAdapter();  
		    	    zonesImageAdapter.notifyDataSetChanged(arg2);  
		    	    }    
		    	   public void onNothingSelected(AdapterView<?> arg0) {  
		    	        // TODO Auto-generated method stub  
		    	           
		    	    }           
		    	});
		
	}

	@Override
	protected void onStart() {
		super.onStart();
		// new Thread(downloadInfoRun).start();
	}

}

    

package com.video.browse.adapter;

import java.util.ArrayList;
import java.util.List;

import com.video.browse.R;
import com.video.browse.util.FileVoideInfo;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.ImageView.ScaleType;

public class VideoAdapter extends BaseAdapter {
	int mGalleryItemBackground;
	private Context mContext;
	private static final String TAG = "VideoAdapter";
	List<FileVoideInfo> list = new ArrayList<FileVoideInfo>();
	private int selected = -1;
	
	public VideoAdapter(Context context,List<FileVoideInfo> list) {
		this.mContext = context;
		this.list = list;
		
	}
	
	@Override
	public int getCount() { 
		Log.i(TAG,"adapter list size: "+list.size());
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}
	
	public void notifyDataSetChanged(int id) {
		selected = id;
		super.notifyDataSetChanged();
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ImageView imgView = new ImageView(mContext);
		imgView.setLayoutParams(new GridView.LayoutParams(285, 185));
		imgView.setPadding(228, 228, 228, 228);
		imgView.setBackgroundResource(R.drawable.nba_4);
		if (selected == position) {
			imgView.setScaleType(ImageView.ScaleType.CENTER_CROP);
			Animation testAnim = AnimationUtils.loadAnimation(mContext,R.anim.anim);
			imgView.startAnimation(testAnim);
		} else {
			imgView.setScaleType(ImageView.ScaleType.CENTER);
		}
		return imgView;
	}

}

 

package com.video.browse.ui;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.GridView;

public class VideoGridView extends GridView {
	private int position = 0;
	public VideoGridView(Context context) {
		super(context);
	}

	public VideoGridView(Context context, AttributeSet attrs) {
		super(context, attrs);
		setChildrenDrawingOrderEnabled(true);
	}

	public void setCurrentPosition(int pos) {// 刷新adapter前,在activity中调用这句传入当前选中的item在屏幕中的次序
		this.position = pos;
	}

	@SuppressLint("NewApi")
	@Override
	protected void setChildrenDrawingOrderEnabled(boolean enabled) {
		// TODO Auto-generated method stub
		super.setChildrenDrawingOrderEnabled(enabled);
	}

	@Override
	protected int getChildDrawingOrder(int childCount, int i) {
		if (i == childCount - 1) {// 这是最后一个需要刷新的item
			return position;
		}
		if (i == position) {// 这是原本要在最后一个刷新的item
			return childCount - 1;
		}
		return i;// 正常次序的item
	}

}

     

<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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    
     -->

   <com.video.browse.ui.VideoGridView
        android:id="@+id/gridview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:columnWidth="210dp"
        android:gravity="center"
        android:horizontalSpacing="1dp"
        android:numColumns="auto_fit"
        android:verticalSpacing="1dp" />

</RelativeLayout>

 

 



 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值