I want to bind my ImageView control to my property URL (it's my image local path like this : /storage/emulated/0/MyFolder/IMG_20160411_094834.JPEG
I try to bind my control like this :
<ImageView
android:src="#android:drawable/ic_menu_gallery"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/ImagePreview"
local:MvxBind="ImageUrl ImagePath" />
ImagePath is my property but i can't use this method.
Can you help me ?
Thank you
You have to use Mvx.MvxImageView.
Changing ImageView to Mvx.MvxImageView should fix it.
Ensure, that you have installed the
File plugin (https://www.nuget.org/packages/MvvmCross.Plugin.File/)
DownloadCache plugin (https://www.nuget.org/packages/MvvmCross.Plugin.DownloadCache/)
in your android and core project.
Related
So the simple idea is that I have SVG data as a string that I fetch from Internet.
I would like to show that as an icon in my app. Is there any way I can do this?
I have seen countless examples where SVG data is in a file located in the app's directory that is then showed but this is not what I am looking for. I literally have the data in XML format after http request and I only need to transform that to a Image or something else visible on the screen.
I have been trying to find a solution to this for hours now, so I would really appreciate some help :S
Android doesn't support svg with ImageView directly,you could display SVG with some commonly used third-party controls.
Like FFImageLoading.
Add Xamarin.FFImageLoading.Svg nuget package to platform project. Use ImageService with svg data resolver for displaying svg images.
For Android:
<ImageView
android:id="#+id/image_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
then use like:
var svgString = #"<svg><rect width=""30"" height=""30"" style=""fill:blue"" /></svg>";
ImageView imageView = FindViewById<ImageView>(Resource.Id.image_view);
ImageService.Instance
.LoadString(svgString)
.LoadingPlaceholder(placeHolderPath)
.WithCustomDataResolver(new SvgDataResolver(64, 0, true))
.WithCustomLoadingPlaceholderDataResolver(new SvgDataResolver(64, 0, true))
.Into(imageView);
I am getting a response from JSON API where a "Video" tag contains a video or image name with its extension as shown below. I want to show video if that tag contains video (I am loading video in Web view) then hide Image view, or show image if it contains image then hide Web view.
Problem coming is that webview visibility is gone if the response postion has .mp4 and image view is visible but response image is not showing in Picasso.
Response:
[
{
"Video": "8100931.mp4"
},
{
"Video": "218519.jpeg",
}]
Layout:
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/llVideoPost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="visible">
<WebView
android:id="#+id/wvPostVideo"
android:layout_width="match_parent"
android:layout_height="0dp"
android:focusable="false"
android:screenReaderFocusable="false"
android:visibility="visible"
app:layout_constraintDimensionRatio="1:1"
tools:ignore="MissingConstraints" />
<ImageView
android:id="#+id/imgPostImage"
android:layout_width="match_parent"
android:layout_height="0dp"
android:contentDescription="#string/todo"
android:scaleType="fitXY"
android:visibility="gone"
app:layout_constraintDimensionRatio="1:1"
tools:ignore="MissingConstraints" />
</androidx.constraintlayout.widget.ConstraintLayout>
I tried this code
Code for calling response:
String videoTag= businessList.get(position).getVideo();
if (businessList.get(position).getVideo().endsWith(".mp4")) {
holder.wvPostVideo.setVisibility(View.VISIBLE);
holder.imgPostImage.setVisibility(View.GONE);
holder.wvPostVideo.loadUrl("https://smakerspace.s3.ap-south-1.amazonaws.com/Video/" + videoTag);
} else if (businessList.get(position).getVideo().endsWith(".jpeg")) {
holder.wvPostVideo.setVisibility(View.GONE);
holder.imgPostImage.setVisibility(View.VISIBLE);
Picasso.get()
.load("https://smakerspace.s3.ap-south-1.amazonaws.com/upload/"+videoTag)
.rotate(90)
.into(holder.imgPostImage);
}
replace https://smakerspace.s3.ap-south-1.amazonaws.com/upload/ with https://smakerspace.s3.ap-south-1.amazonaws.com/Video/
Becuase you have stored these image and video file into one db folder
And please use Videoview for video player its make eassy to play a video into android
Instead of passing url to picasso, can you please first try to download the image programmatically and then try to set to any ImageView.
Or you can use any rest clients to validate if APIs are working fine and returning valid image.
Once above is validated and found to be working fine, next step is to check if we got right instance of imgPostImage
I am new to Xamarin Android Application.I use Picasso component to cache and download Images and It works fine.
Picasso.With (this.Activity).Load ("Here I pass Url").Into (imageview);
Now I am using MvvmCross binding like:
<Mvx.MvxImageView
android:layout_width="120dp"
android:layout_height="140dp"
android:id="#+id/ProductImageView"
android:scaleType="fitXY"
local:MvxBind="ImageUrl URL" />
Here URL is a string which I set in Viewmodel.My problem is, it downloads image but can not cache that image like picasso does.Can anyone suggest me what to do?
How to use Picasso to bind and cache image ?
There's nothing magic about MvxImageView - it's class a class that inherits from ImageView and exposes a public string ImageUrl property that you can use in binding.
You don't have to use MvxImageView - you can create your own PicassoImageView and expose a property:
private string _i;
public string ImageUrl
{
get { return _i; }
set {
if (_i == value) return;
_i = value;
if (string.IsNullOrEmpty(value)) {
// what do you want to do here? clear the view? use a placeholder?
return;
}
Picasso.With (this.Context).Load (_i).Into (this);
}
}
That sort of thing should work...
...With bonus points if you blog/write about how you get this working and what you learn along the way (or if you publish a nuget package that others can use)
You can cache an image with Picasso without loading it in any ImageViewers like this:
Picasso. with(Context). load(ImageFile.Url). into(null);
But im not sure how you can use this later.
You can try your own implementation of caching, it's easy, check this article
I have successfully used MvxImageView with ImageUrl, but how can I set a drawable icon as a default for those users which don't have a profilepicture (that is, where ProfileThumbnailImageUrl is empty)?
<MvxImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
local:MvxBind="ImageUrl ProfileThumbnailImageUrl"
DefaultImagePath="#drawable/ic_action_user"/>
If this view is just being used once (e.g. not reused in a list) then you can just use android:src for your default image.
If you need to use DefaultImagePath then you can do this in a binding:
local:MvxBind="ImageUrl ProfileThumbnailImageUrl; DefaultImagePath DefaultImageUrl"
where DefaultImageUrl is a drawable accessed as res:name - e.g. res:ic_action_user, a file path (saved using the File plugin), or an http url
You should also be able to do this as a string literal:
local:MvxBind="ImageUrl ProfileThumbnailImageUrl; DefaultImagePath 'res:ic_action_user'"
In a typical as3 or flex project, after loading xml file, i load jpg files (thumbnails etc) manually, so i can use them in sprites / movie clips etc..
currently i am working on air mobile project. and i am attempting to load some thumnails(jpg) file to list view (spark) and using custom item renderer.
itemrenderer has an spark image component in it. and its data property is set to Image object.
i can check that image files do exists in file application directory.
do i need to load all those thumbnails in memory. then use them?
image object will autoload source file object?? once assigned?
do i have to tell it explicitly to load file object? what events should i use to amke sure , image file object is loaded.?
any ideas?
thanks in advance.
Spark images are really easy to work with. All you need is a url.
<s:Image source="http://someimagesite.com/someimage.png" width="100%" height="100%" />
You can also use bitmap data or even embed directly into the source tag.
[Embed(source="image.png")] private var myImage:Class
mySparkImage.source = new myImage() as BitmapData;
<s:Image source="#Embed('image.png')" />
Take a look:
http://help.adobe.com/en_US/flex/using/WSc5cd04c102ae3e97-33ad5caa12c719dc7c8-8000.html