Created
January 20, 2015 19:19
-
-
Save sescandell/e2079e2444a50dc3b23e to your computer and use it in GitHub Desktop.
MvvmCross: Droid - Workaround for Android Images issues (OOM). Based on the use of AQuery: https://code.google.com/p/android-query/ (https://github.com/androidquery/androidquery) and its Xamarin binding https://github.com/Kiranbhat2005/AQueryXamarin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Android.Content; | |
using Android.Util; | |
using Android.Widget; | |
using System; | |
using Com.Androidquery; | |
namespace Sescandell.App.Mobile.Droid.Views.Controls | |
{ | |
class AQImageView : ImageView | |
{ | |
private readonly AQuery aQuery; | |
private int _defaultSource; | |
public AQImageView(Context context, IAttributeSet attrs) | |
: base(context, attrs) | |
{ | |
aQuery = new AQuery(this); | |
_defaultSource = attrs.GetAttributeResourceValue("http://schemas.android.com/apk/res/android", "src", 0); | |
} | |
public int FallbackResource | |
{ | |
get { return _defaultSource; } | |
set { _defaultSource = value; } | |
} | |
private string _imageUrl; | |
public string ImageUrl | |
{ | |
get { return _imageUrl; } | |
set | |
{ | |
_imageUrl = value; | |
if (!String.IsNullOrEmpty(_imageUrl)) | |
{ | |
aQuery.Image(_imageUrl, true, true, 0, _defaultSource); | |
} | |
else | |
{ | |
SetImageResource(_defaultSource); | |
} | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
<!-- Using hard coded common default image --> | |
<AQImageView | |
android:id="@+id/MyImageViewId" | |
android:layout_width="45dp" | |
android:layout_height="45dp" | |
android:layout_alignParentLeft="true" | |
android:layout_alignParentTop="true" | |
android:src="@drawable/default_image" | |
local:MvxBind="ImageUrl MyObject.MyPropertyPicture" | |
android:layout_margin="5dp" /> | |
... | |
<!-- Using Binding for default image. --> | |
<!-- Known issues: fallback Binding must be define before ImageUrl one --> | |
<!-- Note here the android:src parameter is useless --> | |
<AQImageView | |
android:id="@+id/MyOtherImageViewId" | |
android:layout_width="45dp" | |
android:layout_height="45dp" | |
android:layout_alignParentLeft="true" | |
android:layout_alignParentTop="true" | |
android:src="@drawable/default_image" | |
local:MvxBind="FallbackResource MyConverter(MyObject.SomeProperty); ImageUrl MyObject.MyPropertyImage" | |
android:layout_margin="5dp" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment