【问题标题】:Images will not display in MultiImageView component图像不会显示在 MultiImageView 组件中
【发布时间】:2014-08-03 15:29:47
【问题描述】:
在 Xamarin 中,如何使用此链接中的 MultiImageView 组件显示图像:http://components.xamarin.com/view/MultiImageView?
这是我从网页获得的代码:
base.OnCreate(bundle);
MultiImageView imageView = new MultiImageView (this);
imageView.LoadImageList(new [] {
"http://blog.xamarin.com/wp-content/uploads/2013/01/evolve-badge.png",
"http://oi50.tinypic.com/dfzo0k.jpg",
"http://oi49.tinypic.com/kd6fcp.jpg"});
imageView.ImagesLoaded += (sender, e) =>
{ // Loads the first image in the list
RunOnUiThread(imageView.LoadImage);
};
应用程序编译,但没有显示图像。另外,没有错误。
我必须使用布局吗?
我可以就这段代码寻求帮助吗?
提前致谢
【问题讨论】:
标签:
android
android-layout
imageview
xamarin
components
【解决方案1】:
您不会在任何地方将MultiImageView 添加到您的 UI 布局中。
尝试将其添加到现有布局中(例如 LinearLayout)以使其正常工作:
主要活动
// ...
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
var view = FindViewById<LinearLayout> (Resource.Id.viewContent);
MultiImageView imageView = new MultiImageView (this);
imageView.LoadImageList(new [] {
"http://blog.xamarin.com/wp-content/uploads/2013/01/evolve-badge.png",
"http://oi50.tinypic.com/dfzo0k.jpg",
"http://oi49.tinypic.com/kd6fcp.jpg"});
imageView.ImagesLoaded += (sender, e) =>
{ // Loads the first image in the list
RunOnUiThread(imageView.LoadImage);
};
view.AddView (imageView);
}
// ...
Main.axml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/viewContent">
</LinearLayout>