我目前正在使我的應用程序的一部分,以使用GridView從圖庫中選擇多個圖像。 問題是我需要在第一個項目上放一個按鈕,其餘的將是圖像(0,0將是按鈕,其餘部分會很好,帶有複選框的imageview)該按鈕將使用手機攝像頭。我能做到,但作爲交換,它不能順利滾動,有沒有辦法解決這個問題?以下是我的代碼:Android Gridview平滑滾動按鈕
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
View view;
System.out.println(position);
if (position == 0) {
holder = new ViewHolder();
view = getLayoutInflater().inflate(R.layout.year_dropdownlayout, parent, false);
holder.mButton = (Button) view.findViewById(R.id.mfreakingBtn);
ViewGroup.LayoutParams params = holder.mButton.getLayoutParams();
params.height = 250;
params.width = 250;
holder.mButton.requestLayout();
} else {
view = getLayoutInflater().inflate(R.layout.select_photos_layout, parent, false);
holder = new ViewHolder();
holder.imageView = (ImageView) view.findViewById(R.id.imageView1);
holder.mCheckBox = (CheckBox) view.findViewById(R.id.checkBox1);
holder.mCheckBox.setOnCheckedChangeListener(mCheckedChangeListener);
holder.progressBar = (ProgressBar) view.findViewById(R.id.progress);
holder.mButton = null;
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "You Clicked " + position, Toast.LENGTH_LONG).show();
}
});
imageLoader.displayImage("file://" + imageUrls.get(position), holder.imageView, options, new SimpleImageLoadingListener() {
@Override
public void onLoadingStarted(String imageUri, View view) {
holder.progressBar.setProgress(0);
holder.progressBar.setVisibility(View.VISIBLE);
}
@Override
public void onLoadingFailed(String imageUri, View view,
FailReason failReason) {
holder.progressBar.setVisibility(View.GONE);
}
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
Animation anim = AnimationUtils.loadAnimation(MultiPhotoSelect.this, R.anim.fade_in);
holder.imageView.setAnimation(anim);
anim.start();
holder.progressBar.setVisibility(View.GONE);
}
}, new ImageLoadingProgressListener() {
@Override
public void onProgressUpdate(String imageUri, View view, int current,
int total) {
holder.progressBar.setProgress(Math.round(100.0f * current/total));
}
}
);
holder.mCheckBox.setTag(position);
holder.mCheckBox.setChecked(mSparseBooleanArray.get(position));
}
return view;
}
不介意佈局的名稱。 :)當挫折感到雅時,會發生什麼。我一直在尋找幾個小時。我發現一個人在gridview的末尾放了一個按鈕:Android - Different items in GridView not showing up
我希望有人能幫助我。提前致謝。 :)
這是因爲你總是膨脹新的視圖實例。檢查convertView實例是否爲null。如果爲空,那麼這是唯一一次應該誇大視圖的時間。 請參閱BaseAdapter.getItemViewType(),BaseAdapate.getItemViewTypeCount()。 看到這個:http://www.learn2crack.com/2014/01/android-custom-gridview.html – 2014-09-11 10:26:09