2017-08-27 358 views
-2

我已經填充GridView與一些grid_items如何膨脹GridView適配器中的佈局

我正在尋找一種方式來誇大一個新的佈局(我們稱之爲pop_up_layout.xml),將只佔據屏幕的一部分,該事件應該點擊放置在一個特定grid_item視圖按鈕時觸發。我知道我必須將功能放在適配器當前項目的位置。

我的目的是爲了顯示對grid_item更多信息,以及在正在膨脹的pop_up_layout.xml提供通過新的按鈕用戶新的選擇。

我已經搜索並瀏覽了大部分與SO相關的問題以及網站,但我似乎只找到解決方案來顯示彈出式視圖。

有人能指出我正確的方向嗎? 類似this是我正在尋找。

+0

你可以使用dialogfragment對於這一點,你可以從網格視圖數據發送到片段,以便它可以顯示出相對內容 –

回答

1

您可以使用DialogFragment爲您的案件充氣佈局不是完美的答案。

要打開,你可以在你的網格項的點擊使用片段

FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction(); 
     BaseDialogFragment Fragment = new BaseDialogFragment(); 
     transaction.add(fragment, "loading"); 
     Bundle args = new Bundle(); 
     args.putString("your_data", yourdata); 
// you can add as many string int or boolean. Explore it. 
     fragment.setArguments(args); 
     transaction.commitAllowingStateLoss(); 





    public class BaseDialogFragment extends DialogFragment { 

      Typeface MR, MRR; 

      @Override 
      public void onViewCreated(View view, Bundle savedInstanceState) { 
       super.onViewCreated(view, savedInstanceState); 
       getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); 
       getDialog().setCanceledOnTouchOutside(false); 



      } 

      @Override 
      public void onStart() { 

       super.onStart(); 

       Window window = getDialog().getWindow(); 
       WindowManager.LayoutParams windowParams = window.getAttributes(); 
       windowParams.dimAmount = 0.50f; 

       window.setAttributes(windowParams); 
      } 

      public void onResume() { 

       super.onResume(); 
       WindowManager.LayoutParams params = getDialog().getWindow().getAttributes(); 
       params.width = RelativeLayout.LayoutParams.MATCH_PARENT; 
       params.height = RelativeLayout.LayoutParams.WRAP_CONTENT; 
       params.gravity = Gravity.CENTER; 
       getDialog().getWindow().setAttributes(params); 



      } 

      @Nullable 
      @Override 
      public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 

       View v = inflater.inflate(R.layout.yourlayout, container, false); 

       // init your views here. or 
get the data here from the Grid View 
       String your_data = getArguments().getString("your_data"); 

       return v; 
      } 
     } 
+0

謝謝您的回覆。你的答案是專注,它有我需要的一切,很好的解釋。我會盡快實施並測試它。關於實際的代碼,我確實有一些問題,因爲我不喜歡編寫我沒有完全理解的代碼。如果你有時間我可以留下評論。關於我收到的惡意軟件,我真的很想看到實際給予它的人的解釋。至少我可以更好地過濾我的話,並在未來改善我的問題。 –