我对xamarin.android相当新,我在滚动视图中有一个图像视图,我想在点击时放大它。 (当在用户点击图像时显示完整图像onclick就像在移动Facebook上一样)我希望它在全屏幕中打开。我如何实现这一目标?
我已做过一些研究,无法找到一些有用的线程......任何帮助都会被提前感谢你。
继承我的细节性课程
private ImageView mtimg0, mtimg1, mtimg2, mtimg3, mtimg4, mtimg5;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.detailLayout);
FindViews();
Android.Content.Intent i = this.Intent;
string iname = i.Extras.GetString("MTNAME");
int iimg0 = i.Extras.GetInt("IMG0");
int iimg1 = i.Extras.GetInt("IMG1");
int iimg2 = i.Extras.GetInt("IMG2");
int iimg3 = i.Extras.GetInt("IMG3");
int iimg4 = i.Extras.GetInt("IMG4");
int iimg5 = i.Extras.GetInt("IMG5");
mtimg0.SetImageResource(iimg0);
mtimg1.SetImageResource(iimg1);
mtimg2.SetImageResource(iimg2);
mtimg3.SetImageResource(iimg3);
mtimg4.SetImageResource(iimg4);
mtimg5.SetImageResource(iimg5);
}
private void FindViews()
{
tmtname = FindViewById<TextView>(Resource.Id.mtname);
mtimg0 = FindViewById<ImageView>(Resource.Id.mtimg00);
mtimg1 = FindViewById<ImageView>(Resource.Id.mtimg01);
mtimg2 = FindViewById<ImageView>(Resource.Id.mtimg02);
mtimg3 = FindViewById<ImageView>(Resource.Id.mtimg03);
mtimg4 = FindViewById<ImageView>(Resource.Id.mtimg04);
mtimg5 = FindViewById<ImageView>Resource.Id.mtimg05);
}
}
EDITED
这是我的列表视图中的项目示例,其中我获取了所有图片
class MountainsData
{
public static List<Mountain> MountainList = new List<Mountain>()
{
new Mountain()
{
MtName = "ALTO PEAK",
Masl = 1332,
Difficulty = 6,
Island = 2,
MtImg00 = Resource.Drawable.altopeak,
MtImg01 = Resource.Drawable.altopeak1,
MtImg02 = Resource.Drawable.altopeak2,
MtImg03 = Resource.Drawable.altopeak3,
MtImg04 = Resource.Drawable.altopeak4,
Location = "ORMOC, LEYTE",
JumpOff ="Lake Danao National Park, Ormoc",
Description ="LLA: 11.1061 N, 124.7097 E, 1332
}
并在我的列表中查看活动..这里是我如何将每个项目传递给我的详细活动...并在我的详细活动中收到它我使用上面的代码(在细节性课上..这个问题上面的第一个代码)
private List<Mountain> mMountains;
private void OpenDetailActivity(int pos)
{
mt = mMountains[pos];
i = new Intent(this, typeof(DetailActivity));
i.PutExtra("IMG0", mt.MtImg00);
i.PutExtra("IMG1", mt.MtImg01);
i.PutExtra("IMG2", mt.MtImg02);
i.PutExtra("IMG3", mt.MtImg03);
i.PutExtra("IMG4", mt.MtImg04);
i.PutExtra("IMG5", mt.MtImg05);
i.PutExtra("MTNAME", mt.MtName);
i.PutExtra("LOCATION", mt.Location);
i.PutExtra("JUMPOFF", mt.JumpOff);
i.PutExtra("DESCRIPTION", mt.Description);
i.PutExtra("BACKGROUND", mt.Background);
i.PutExtra("ITINERARY", mt.Itinerary);
i.PutExtra("PRACTICALITIES", mt.Practicalities);
i.PutExtra("ATTIRE", mt.Attire);
i.PutExtra("TTB", mt.Ttb);
StartActivity(i);
}
我想要在细微差别中发生的事情是当我点击图像视图时......在全屏显示它但我无法找到正确传递字符串的方法..提前谢谢你:D
答案 0 :(得分:0)
这是DialogFragment的解决方案:
您的fragment_dialog.axml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="2000dp"
android:minHeight="2000dp">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/img"
android:src="@drawable/aaa"
android:scaleType="fitCenter"/>
</LinearLayout>
您的MyDialogFragment.cs
public class MyDialogFragment : DialogFragment
{
private ImageView imgView;
static public MyDialogFragment newInstance()
{
MyDialogFragment f = new MyDialogFragment();
return f;
}
public override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetStyle(DialogFragmentStyle.NoTitle, Android.Resource.Style.ThemeBlackNoTitleBarFullScreen);
}
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
base.OnCreateView(inflater, container, savedInstanceState);
View v = inflater.Inflate(Resource.Layout.fragment_dialog, container, false);
imgView = v.FindViewById<ImageView>(Resource.Id.img);
//Get int and set it to the ImageView
int imgPassed = Arguments.GetInt("imgId");
imgView.SetImageResource(imgPassed);
return v;
}
}
来自您的ItemSelected或Click事件
FragmentTransaction ft = FragmentManager.BeginTransaction();
DialogFragment newFragment = MyDialogFragment.newInstance();
//Declare String and get the Id
string imgName = "bbb"; //Change with the name of the image you want to pass
int imgId = Resources.GetIdentifier(imgName, "drawable", PackageName);
//Pass it with the Bundle class
Bundle bundle = new Bundle();
bundle.PutInt("imgId", imgId);
newFragment.Arguments = bundle;
//Show the Fragment
newFragment.Show(ft, "dialog");
修改强> 我使用Bundle类作为将数据从Activities传递到Fragments的可能方法之一。对我来说很好。
获得相同结果的另一种方法是使用其他活动和意图,您可以在此处找到所需的一切:Passing Data Between Activities