this is my code:
final ImageView imageView1 = (ImageView) findViewById(R.id.imageView8);
imageView1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
imageView1.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT));
}
});
by this code when i click on my ImageView i can see it in fullScreen.
Now i have a question:
when I see imageView in fullscreen I want when I press Back, this imageView close and back to previous situation and my app doesn't back to previous activity
Rather then opening an image on full screen you can use a custom dialog to open that image which is called a Full Image Dialog, which works exactly as AlertDialog, for that you just need to design a custom layout including width and height of image you are opening. It is easy to maintain as on clicking anywhere on screen dialog automatically closes and your activity will resume.
If you want then I can give you more idea?
Step 1: Make a class FullImageDialog having this method:
public static void showImage(Context context, String strImagePath) {
AlertDialog.Builder imageDialog = new AlertDialog.Builder(context);
LayoutInflater inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.custom_fullimage_dialog, null);
ImageView image = (ImageView) layout.findViewById(R.id.fullImage);
Glide.with(context)
.load(strImagePath)
.placeholder(R.drawable.default_user_image)
.dontAnimate()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(image);
//image.setImageDrawable(tempImageView.getDrawable());
imageDialog.setView(layout);
final AlertDialog alert= imageDialog.create();
alert.getWindow().getAttributes().windowAnimations=R.style.FadeInTheme;
alert.show();
}
Step 2: create xml of full_image_dialog as:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/layout_root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:id="#+id/fullImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:background="#drawable/default_user_image"
android:scaleType="fitXY" />
</LinearLayout>
step 3: call method where you need to open this dialog:
final ImageView imageView1 = (ImageView) findViewById(R.id.imageView8);
imageView1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//call FullImageDialog class by giving parameter of imageUrl
FullImageDialog.showImage(imageUrl);
}
Related
Code:
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
image_person = (ImageView) findViewById(R.id.dialog_imageview);
}
public void checkBox_checker(String checkerID, String checkerName, String checkerSurname, String
checkerDescription, Blob picture) throws SQLException
{
int blobLength = (int) picture.length();
byte[] bytes = picture.getBytes(1,blobLength);
Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
Log.d(TAG, "Checker box");
LayoutInflater factory = LayoutInflater.from(MainActivity.this);
final View alertDialog= factory.inflate(R.layout.sample, null);
image_person.setImageBitmap(bitmap);
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setCancelable(true);
builder.setView(alertDialog);
builder.setTitle("Information");
builder.setMessage(message);
builder.setNegativeButton("Report", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
}
});
builder.setPositiveButton("Enter", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
}
});
builder.show();
}
Sample.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity">
<ImageView
android:id="#+id/dialog_imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
My problem is that the image is inserted behind the alert dialog and not inside the alert dialog. Can someone help me as to why this is happening?
I have entered the image in the xml file and it does get displayed in the alert dialog. So not too sure why this is happening.
It looks like you have a separate ImageView called dialog_imageview inside the layout activity_main. Otherwise, the activity wouldn't be able to find a View here:
image_person = (ImageView) findViewById(R.id.dialog_imageview);
which then would cause a Null Pointer Exception a few lines below:
image_person.setImageBitmap(bitmap);
To fix all of this, delete the dialog_imageview from activity_main XML layout.
Then, find the correct ImageView in your inflated sample layout rather than in the activity by calling findViewById on it:
final View alertDialog = factory.inflate(R.layout.sample, null);
image_person = (ImageView) alertDialog.findViewById(R.id.dialog_imageview);
image_person.setImageBitmap(bitmap);
You cannot do a "findViewById()" before have Inflated its Layout...
I think you have a "dialog_imageview" in your MainActivity's Layout and then the Image is updated in the wrong ImageView.
You just have to move "image_person = (ImageView)alertDialog.findViewById(R.id.dialog_imageview);" after the "factory.inflate(R.layout.sample, null);" row.
Firstly as Hoffman pointed out correctly, I did duplicate the ImageView in the activty_man.xml.
However, the problem still persisted.
After much investigations, I realized I missed a single line of code,
Before:
image_person = (ImageView) findViewById(R.id.dialog_imageview);
After/Correction:
image_person = (ImageView) alertDialog.findViewById(R.id.dialog_imageview);
So I have a ListView with list-items that each have different images in them. I have my code setup so that when the user clicks an image, it will show an expanded version of that particular image by using the Dialog class.
However, no matter what code I've tried, it doesn't seem like I can make the Dialog image change! Am I not able to modify layout elements from within an adapter? I could only figure out how to reference my individual list-item images by putting the relevant code within my adapter.
What needs to change, and what am I doing wrong?
Here's the applicable code in my adapter for reference:
viewHolder.image.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.i(LOG_TAG, "Calling ImageView OnClickListener");
int imageId = currentWord.getImageResourceId();
Dialog aD = new Dialog(mContext);
LayoutInflater layoutInflater = LayoutInflater.from(mContext);
View popupLayout = layoutInflater.inflate(R.layout.popup_image_layout, null);
ImageView popupImageView = (ImageView) popupLayout.findViewById(R.id.popup_imageView);
Glide
.with(mContext)
.load(imageId)
.apply(new RequestOptions().circleCrop())
.into(popupImageView);
aD.setContentView(R.layout.popup_image_layout);
aD.show();
}
});
Thanks for any of your help!
So I ended up figuring the answer out on my own.
Under aD.setContentView(), I should have had popupLayout as the target, which had already had R.layout.popup_image_layout assigned and inflated in the same line... By referencing the layout anew, the code wasn't actually inflating the layout, so there was nothing able to be shown.
So all that needed to be changed was: modifying aD.setContentView(R.layout.popup_image_layout) to aD.setContentView(popupLayout) and now when I click on the individual images in my ListView items, the proper image for each pops up in an expanded ImageView, which is shown by way of the Dialog class.
UPDATE:
Added some extra code in order to make sure that the Dialog is completely removed after being closed. Otherwise, it is kept in memory and the memory use continues to stack and increase indefinitely upon each subsequent Dialog being opened.
Updated code below:
Dialog aD = null;
final int imageId = currentWord.getImageResourceId();
final LayoutInflater layoutInflater = LayoutInflater.from(mContext);
viewHolder.image.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
View popupLayout = layoutInflater.inflate(R.layout.popup_image_layout, null);
final ImageView popupImageView = (ImageView) popupLayout.findViewById(R.id.popup_imageView);
if (aD == null) {
aD = new Dialog(mContext);
aD.getWindow().setBackgroundDrawableResource(R.color.transparent);
}
Log.i(LOG_TAG, "Calling ImageView OnClickListener");
Glide
.with(mContext)
.load(imageId)
.apply(new RequestOptions().circleCrop())
.into(popupImageView);
aD.setContentView(popupLayout);
aD.show();
popupLayout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
aD.dismiss();
aD = null;
}
});
}
});
What the title says. At first, I created a method to swap from one image to the other one, and it works. When I add the 2nd method though, to reverse the action and swap back to the first one, nothing changes. It does not even revert from the first image to the second one. Below is the code:
public void fade(View view) {
ImageView laxus = (ImageView) findViewById(R.id.laxus_shirt);
ImageView laxos2 = (ImageView) findViewById(R.id.laxus2);
laxus.animate().alpha(0f).setDuration(1000);
laxos2.animate().alpha(1f).setDuration(1000);
}
public void fadetoblack(View view) {
ImageView laxusius = (ImageView) findViewById(R.id.laxus_shirt);
ImageView laxosios2 = (ImageView) findViewById(R.id.laxus2);
laxosios2.animate().alpha(0f).setDuration(1000);
laxusius.animate().alpha(1f).setDuration(1000);
}
Thank you in advance.
You need to call start() to trigger the animation.
laxus.animate().alpha(0f).setDuration(1000).start();
laxos2.animate().alpha(1f).setDuration(1000).start();
I would suggest you to use Util method to perform crossfading. Something like below
public static void crossFade(View incomingView, View outGoingView, int outGoingViewVisibility) {
outGoingView.setAlpha(1);
ViewCompat.animate(outGoingView).alpha(0).setListener(new ViewPropertyAnimatorListener() {
#Override
public void onAnimationStart(View view) {
}
#Override
public void onAnimationEnd(View view) {
view.setVisibility(outGoingViewVisibility);
}
#Override
public void onAnimationCancel(View view) {
}
}).start();
incomingView.setVisibility(View.VISIBLE);
incomingView.setAlpha(0);
ViewCompat.animate(incomingView).setListener(null).alpha(1).start();
}
Maybe it will be an option to use ViewSwitcher.
Add a viewSwitcher with 2 ImageViews.
<ViewSwitcher xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/switcher"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/laxus"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<ImageView
android:id="#+id/laxus2"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</ViewSwitcher>`
On Activity onCreate add code
ViewSwitcher viewSwitcher=(ViewSwitcher)findViewById(R.id. switcher); // initiate a ViewSwitcher
Animation in = AnimationUtils.loadAnimation(this,android.R.anim.slide_in_left); // load in animation
Animation out = AnimationUtils.loadAnimation(this,android.R.anim.slide_out_right); // load out animation
viewSwitcher.setInAnimation(in); // set in Animation for ViewSwitcher
viewSwitcher.setOutAnimation(out); // set out Animation for ViewSwitcher
When you want to switch between ImageViews call method viewSwitcher.showNext(); or viewSwitcher.showPrevious();
To verify which view is displayed use viewSwitcher.getCurrentView();
I guess that you know the ICS contact application.
There is a fancy and usefull way to display pictures in a cropped way and then on a click, the full picture appear.
I just wanted to know how to achieve this..
Is that a new Activity?
Should I create a popup with the full picture and create the animation in the same Activity?
Thank a lot for any help..
I have already tried:
final ImageView imageView = (ImageView) findViewById(R.id.imageView);
imageView.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
AlertDialog.Builder builder = new AlertDialog.Builder(
ActivityDetail.this);
ImageView view = new ImageView(ActivityDetail.this);
//build the view
builder.setView(view);
builder.create().show();
}
});
The big problem is the animation!
The dialog is not as neat as the Contact apps.
you can use scaleType attribute of ImageView like this,
<ImageView android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="center"
android:src="#drawable/eureka"
android:scaleType="matrix">
</ImageView>
android:scaleType has different values given on android:scaleType samples
then,
You can pass the imagesourceid as intent extra somewhat like this.
Intent newintent = new Intent(test.this, image.class);
newintent.putExtra("IMAGE", R.drawable.yor_image);
and then accept in the destination activity and use as below
int imgid = getIntent().getIntExtra("IMAGE", 0);
ImageView img = (ImageView)findViewById(R.id.img);
img.setImageResource(imgid);
I am developing a card game on android, and I am looking to change the Image of an ImageView when a button is pressed to pick a card, and I have looked at several other ideas, but all I have seem either crash or it does not change.
cimg = new ImageView(this);
nextCard.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
cimg.setImageResource(R.drawable.c2);
doCard();
}
});
Here is what I have for code, and with this, the image does not change
XML:
<ImageView android:layout_height="wrap_content" android:layout_width="wrap_content" android:src="#drawable/icon" android:id="#+id/imageView1"></ImageView>
You have to do
cimg = findViewById(R.id.imageView1); // in your onCreate
cimg.setImageResource(R.drawable.c2);
In your snippet you are just creating a new ImageView that isn't added to your Activity's view.
have you tried referencing the ImageView by Id rather than just a new blank one?
ImageView cimg = (ImageView)findViewById(R.id.imageView1);