尝试在 Dialog 中使 ImageView 全尺寸不起作用
Trying to make ImageView full size in Dialog doesn't work
我正在使用 Fragments,我想在我的片段上点击 ImageView
时获得全尺寸图像 mImageReport
。我的第二个布局是 test.xml(用于对话框)。
我正在使用 Picasso
从 URL 获取图像
但问题是我的图像没有出现在新对话框 (mImageReport) 上。我不知道如何 link 来自 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>
从 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();
}
我正在使用 Fragments,我想在我的片段上点击 ImageView
时获得全尺寸图像 mImageReport
。我的第二个布局是 test.xml(用于对话框)。
我正在使用 Picasso
但问题是我的图像没有出现在新对话框 (mImageReport) 上。我不知道如何 link 来自 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>
从 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();
}