Reputation: 6888
I want to use full width of the screen to show dialog and image inside that...
I have written custom xml file to show alert dialog and i have posted complete code which i am using to show image from SDCard into dialog.
Code:
holder.viewImageButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View vi) {
final AlertDialog.Builder imageDialog = new AlertDialog.Builder(UploadActivity.this);
final LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.custom_fullimage_dialog,
(ViewGroup) findViewById(R.id.layout_root));
ImageView image = (ImageView) layout.findViewById(R.id.fullimage);
try
{
fileName = ImageList.get(position).toString().
substring(strPath.lastIndexOf('/')+1, strPath.length());
String fileToView = Environment.getExternalStorageDirectory().getPath() + "/Pictures/Joseph/" + CameraLauncherActivity.folder+ "/" + fileName;
Log.d("FileToDelete", fileToView);
// to get Image
newFile = new File(fileToView); // get the related file on click
// to set Image
image.setImageURI(Uri.fromFile(newFile));
} catch (Exception e) {
// When Error
e.printStackTrace();
image.setImageResource(R.drawable.fail);
}
// to get Name
fileName=ImageList.get(position).toString().substring
(strPath.lastIndexOf('_')+1, strPath.length());
imageDialog.setTitle(fileName);
imageDialog.setView(layout);
imageDialog.setPositiveButton(android.R.string.ok, new
DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int which) {
// to dismiss the dialog
dialog.dismiss();
}
});
imageDialog.create();
imageDialog.show();
}
});
custom_fullimage_dialog.xml:-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_root"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="3"
android:gravity="center">
<ImageView
android:id="@+id/fullimage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@null" />
<TextView
android:id="@+id/custom_fullimage_placename"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:textColor="#FFF" >
</TextView>
</LinearLayout>
Upvotes: 0
Views: 1109
Reputation: 6888
I have resolved the issue, by using below line of code :
image.setScaleType(ImageView.ScaleType.FIT_XY);
Upvotes: 1
Reputation: 1201
You can also use DialogActivity
to show it in full screen. Use simple Activity to show imageview and set its theme as Dialog.
<style name="ThemeDialog" parent="AppBaseTheme">
<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:backgroundDimEnabled">true</item>
</style>
Now startActivity on button's click and in AndroidManifest file set theme of Activity from style.
<activity
android:name=".ActivityName"
android:theme="@style/ThemeDialog" />
Upvotes: 0
Reputation: 481
You can set attributes with WindowManager
. You can try it like that:
Dialog dialog = new Dialog(getActivity());
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialog_custom);
dialog.getWindow().setBackgroundDrawable(getResources().getDrawable(R.drawable.background)); // Optional Background
dialog.setCanceledOnTouchOutside(true);
dialog.setCancelable(true);
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(dialog.getWindow().getAttributes());
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.MATCH_PARENT;
// DO STUFF
// dialog.findViewById(.....)
dialog.show();
dialog.getWindow().setAttributes(lp);
Upvotes: 1