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);
Related
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);
}
I am creating an android studio colouring app and need to have it so that the user can select which image they want to colour. I want it so that they click on an image button on one activity and this changes the background of the next activity that the button takes them to however I have no idea how to go about this. Any help would be greatly appreciated. Thankyou
From what I understand, you want to change the color of the next activity on button click of current activity. So, what you can do is:
button1.setOnClickListener(new View.OnClickListener{
#Override
public void onClick(View view){
Intent intent = new Intent(mContext, MyActivity2.class);
//Implement getDesiredColor to get the color according to your logic
intent.putExtra("color", getDesiredColor());
mContext.startActivity(intent);
}
});
In your second activity's onCreate
onCreate(...){
...
View rootLayout = //Initialize root layout here
Intent intent = getIntent();
if(intent.hasExtra("color")){
rootLayout.setBackgroundColor(intent.getExtra("color"));
}
...
}
Let me know in case you have any doubts.
UPDATE:
With drawable your code will become something like this:
button1.setOnClickListener(new View.OnClickListener{
#Override
public void onClick(View view){
Intent intent = new Intent(mContext, MyActivity2.class);
//Implement getDesiredDrawable to get the drawable according to your logic
intent.putExtra("drawable", getDesiredDrawable());
mContext.startActivity(intent);
}
});
In your second activity's onCreate
onCreate(...){
...
View rootLayout = //Initialize root layout here
Intent intent = getIntent();
if(intent.hasExtra("drawable")){
rootLayout.setBackground(intent.getExtra("drawable"));
//Or if you are using ImageView in your root layout to set the background image (I'm using Picasso here):
//Picasso.with(mContext).load(intent.getExtra("drawable")).into(myBackgroundImageView);
}
...
}
UPDATE 2:
You can have a hashmap mapping each imagebutton with a drawable.
e.g.
HashMap<Integer, Integer> mViewIdToDrawableMap = new HashMap<>();
mViewIdToDrawableMap.put(mImageButton1.getId(), R.drawable.image1);
mViewIdToDrawableMap.put(mImageButton2.getId(), R.drawable.image2);
mViewIdToDrawableMap.put(mImageButton3.getId(), R.drawable.image3);
public int getDesiredDrawable(View view){
return mViewIdToDrawableMap.get(view.getId());
}
How will you call this function:
button1.setOnClickListener(new View.OnClickListener{
#Override
public void onClick(View view){
Intent intent = new Intent(mContext, MyActivity2.class);
//Implement getDesiredDrawable to get the drawable according to your logic
intent.putExtra("drawable", getDesiredDrawable(view));
mContext.startActivity(intent);
}
});
Now, your last question what is rootLayout?
Lets say your activity2 where you want to show this image has somehitng like this as layyout:
<RelativeLayout>
<ImageView
...
android:id="id+/background_imageview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
...
/>
</RelativeLayout>
In your Activity2's onCreate, do somehting like this (after getting the drawable as I explained earlier):
//Here mBackgroundImageView is the background_imageview in your layout
Picasso.with(mContext).load(drawable).into(mBackgroundImageView);
I want to display links which have format such as/sdcard/Pictures/ etc in textview as clickable link with highlight and underline. I often use Linkifyfor display links, however, this does not support storage links (only web, email etc).
Is there any possible way for that?
I would recommend displaying the image in an ImageView in an Activity.
You can put logic in your onClick(View v) to open the contents of the TextView in a new activity:
#Override
public void onClick(View v) {
Intent intent = new Intent(context, ShowImageActivity.class);
intent.putExtra("imageLocation", v.getText());
context.startActivity(intent);
}
Then in your ShowImageActivity's onCreate() :
ImageView jpgView = (ImageView)findViewById(R.id.imageView);
Bitmap bitmap = BitmapFactory.decodeFile("/sdcard/sample-1.jpg");
jpgView.setImageBitmap(bitmap);
setContentView(R.layout.main);
https://stackoverflow.com/a/9509948/5486718
If you need to you can alternatively add a custom intent to the linkify:
String newActivityURL = "content://com.example.yourapp.yourtargetactivity/";
Pattern pattern = Pattern.compile("[/sdcard/]+[[a-f][0-9]]+[.jpg]");
Linkify.addLinks(hashView, pattern, newActivityURL);
I want to be able to click on an ImageView in a list and have it popup on click, like in the Tumblr and Path app.
Does anyone know how this can be done?
PS: I've tired using a dialog already.
I know its old question. but ill add this for future reference.
You can use this library to show image as a Popup. https://github.com/chathuralakmal/AndroidImagePopup
final ImagePopup imagePopup = new ImagePopup(this);
final ImageView imageView = (ImageView) findViewById(R.id.imageView);
imageView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
/** Initiate Popup view **/
imagePopup.initiatePopup(imageView.getDrawable());
}
});
There's a component called PopupWindow, you can find some example of usage here:
http://android-er.blogspot.com.br/2012/03/example-of-using-popupwindow.html
It is slightly similar to a Dialog, but you have more control over it.
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);