Android 适配器中的图像弹出窗口未显示
我试图在我在GridView上设置的基本适配器中实现图像弹出。这是适配器代码Android 适配器中的图像弹出窗口未显示,android,android-layout,baseadapter,android-gridview,Android,Android Layout,Baseadapter,Android Gridview,我试图在我在GridView上设置的基本适配器中实现图像弹出。这是适配器代码 public View getView(final int position, View view, ViewGroup viewGroup) { if(bitmaps.size()==0){ return null; } final View card = inflater.inflate(R.layout.cardlayout,null,fa
public View getView(final int position, View view, ViewGroup viewGroup) {
if(bitmaps.size()==0){
return null;
}
final View card = inflater.inflate(R.layout.cardlayout,null,false);
ImageView imageView = card.findViewById(R.id.imageViewCard);
imageView.setImageBitmap(bitmaps.get(position));
imageView.setTag(position);
imageView.setOnClickListener(onClickListener);
return card;
}
在这里,我得到了CardView中的ImageView,并通过以下方式为弹出窗口设置了OnClickListener
View.OnClickListener onClickListener = new View.OnClickListener() {
Dialog popup_dialog;
@Override
public void onClick(View view) {
popup_dialog = new Dialog(context);
popup_dialog.setContentView(R.layout.popup);
int position = (Integer) view.getTag();
View popup_layout = getLayoutInflater().inflate(R.layout.popup,null);
ImageView imageView_popup = (ImageView) popup_layout.findViewById(R.id.image_preview_2);
imageView_popup.setImageBitmap(bitmaps.get(position));
popup_dialog.create();
popup_dialog.show();
}
};
我已经创建了弹出布局文件
<!-- language: xml -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:layout_width="250dp"
android:layout_height="350dp"
android:layout_gravity="center">
<ImageView
android:id="@+id/image_preview_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
</LinearLayout>
当我点击图片时,我从下面的代码中得到的只是一个空白的弹出窗口。我已尝试检查所有内容,所有值,即位置、位图数组是否存在,但由于某些原因,未设置ImageView。如果有人能帮我解决这个问题,那就太好了。感谢您花时间阅读此内容。尝试为xml格式的ImageView设置android:layout\u width=“match\u parent”android:layout\u height=“match\u parent”