我正在使用片段,当我点击片段上的mImageReport
时,我希望获得完整尺寸的图片ImageView
。我的第二个布局是test.xml(用于Dialog)。
我正在使用Picasso
但问题是我的图像没有出现在新对话框(mImageReport)上。我不知道如何在我的片段中将test.xml中的imageView
链接到我想要的全屏图像...
这是我的代码。
Reports.java:
public class Reports extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (container == null) {
return null;
}
View view = inflater.inflate(R.layout.reports, container, false);
ButterKnife.inject(this, view);
final Dialog nagDialog = new Dialog(getActivity(),android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
nagDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
nagDialog.setCancelable(false);
nagDialog.setContentView(R.layout.test);
Button btnClose = (Button)nagDialog.findViewById(R.id.btnIvClose);
ImageView ivPreview = (ImageView)nagDialog.findViewById(R.id.iv_preview_image);
// Loading image from url in ImageView ... HERE IS THE PROBLEM
Picasso.with(mImageReport.getContext()).load(mCurrentReportString.getUrlImages()).into(ivPreview);
mImageReport.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
nagDialog.show();
}
});
btnClose.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
nagDialog.dismiss();
}
});
return view;
}
test.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView android:layout_width="match_parent"
android:layout_height="match_parent" android:id="@+id/iv_preview_image" />
<Button android:layout_width="match_parent"
android:layout_height="match_parent" android:background="@drawable/fileclose"
android:id="@+id/btnIvClose" android:layout_alignParentRight="true"
android:layout_alignParentTop="true" />
</RelativeLayout>
答案 0 :(得分:4)
从fragment onCreateView或根据您的要求调用此方法......
private void showImage() {
final Dialog nagDialog = new Dialog(getActivity(),android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
nagDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
nagDialog.setCancelable(false);
nagDialog.setContentView(R.layout.test);
Button btnClose = (Button)nagDialog.findViewById(R.id.btnIvClose);
ImageView ivPreview = (ImageView)nagDialog.findViewById(R.id.iv_preview_image);
// Loading image from url in ImageView ... HERE IS THE PROBLEM
Picasso.with(getActivity()).load(mCurrentReportString.getUrlImages()).into(ivPreview);
btnClose.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
nagDialog.dismiss();
}
});
nagDialog.show();
}