2017-01-03 39 views
0

我相當新的xamarin.android,我有一個滾動視圖中的圖像視圖,我想單擊放大它。 (在手機臉書上顯示完整圖像onclick),當用戶點擊圖像時,我希望它在全屏中打開。我該如何實現?如何顯示全屏圖像視圖onlclick

我做了一些研究,找不到一些有用的線程..任何幫助將appriciated謝謝你提前。

我的繼承人detailactivity類

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 
      } 

,並在項目的例子我列表視圖活動..這裏是我如何將每個項目傳遞給我的詳細活動...並在我的詳細活動中接收它我正在使用代碼abo VE(在detailactivity類。在這個問題上面的第一個代碼)

​​

什麼,我想裏面detailactivity發生的是,當我點擊的ImageView ..在全屏幕顯示,但我不能找到一種方法,正確地傳遞字符串..預先感謝您:d

+0

[放大上點擊一個ImageView的]的可能的複製(http://stackoverflow.com/問題/ 22409920 /放大-i-imageview-on-click) – Demitrian

+0

或者只是爲全屏視圖創建一個新的活動。將意圖傳遞給新活動的圖像管道或路徑。 – user1519979

+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或點擊事件

 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"); 

編輯: 我用捆綁類爲可能的方式,從通過一個數據活動的碎片。對我來說工作得很好。

另一種方法具有相同的結果只是被使用另一個活動和意圖,你可以找到你需要的一切在這裏:Passing Data Between Activities

+0

你好先生本·/謝謝你的答案..它幫助了很多..你能告訴我如何從活動傳遞字符串?因爲它似乎沒有收到正確的數據。 –

+0

@KeithJustine我編輯了帖子,如果它適合你,請務必將問題標記爲已回答。如果你需要更多的幫助,請讓我知道:-) –

+0

你好,先生本抱歉,對於遲到的回覆,剛從假期回來..你的回答是非常有幫助的,但我仍然在傳遞字符串時遇到了麻煩..它似乎並沒有收到正確的數據..「int iimg5 = i.Extras.GetInt(」IMG5「);」這行代碼是如何將我的列表視圖中的字符串傳遞給細節活動..只是想知道如何將它傳遞給對話框片段? –