2015-10-29 21 views
1

我正在將iOS應用程序複製到Android中。該應用程序具有信用卡動畫的「錢包」屏幕,請參閱下面的iOS中的應用視頻。我如何在Android中實現類似的功能?將iOS控制器複製到Android

這裏是行動的iOS錢包的視頻 - >Wallet iOS demo

我需要複製這些功能:

  1. 選擇卡時,列表視圖動畫(當你點擊一個卡就切換到位與新的)
  2. 點擊主卡(大一)使一個彈跳動畫,並去卡的細節。
  3. 向主卡上左側滑動也去卡的細節。

這是iOS中用來使其工作的庫是GLStackedViewController

Wallet

回答

2

我結束了從頭開始做它,沒有需要的庫,並使用常規的ListView。

在持有所有卡片的cardHolder片段中,當點擊第一個項目(0)時,卡片反彈,然後進入細節片段,並且當點擊不是第一個的其他項目時,只需更改listview順序並更新適配器,這裏缺少的一件事是點擊之間的卡片動畫,仍然是WIP。

// Click event for single list row 
    list.setOnItemClickListener(new AdapterView.OnItemClickListener() { 

     @Override 
     public void onItemClick(AdapterView<?> parent, View view, 
           final int position, long id) { 

      Log.d(TAG, "Position: " + position); 

      final FragmentAccount fragment = new FragmentAccount(); 

      // Fisrt card 
      if (position == 0) { 
       // Animated bounce effect 
       Animation anim = AnimationUtils.loadAnimation(view.getContext(), R.anim.expand_in); 
       view.startAnimation(anim); 

       // delay click event (anim duration) and go to new fragment 
       new Handler().postDelayed(new Runnable() { 

        public void run() { 
         if (listBalance.get(position).get(TAG_ACCOUNT_BANKACCOUNTS_ID) != null) { 
          ((GlobalVars) getActivity().getApplication()).setIdBankAccount(Integer.valueOf(listBalance.get(position).get(TAG_ACCOUNT_BANKACCOUNTS_ID))); 
          ((GlobalVars) getActivity().getApplication()).setIdGiftCard(0); 
          ((GlobalVars) getActivity().getApplication()).setCardBalance(""); 
         } else if (listBalance.get(position).get(TAG_ACCOUNT_GIFTCARDS_ID) != null) { 
          ((GlobalVars) getActivity().getApplication()).setIdBankAccount(0); 
          ((GlobalVars) getActivity().getApplication()).setIdGiftCard(Integer.valueOf(listBalance.get(position).get(TAG_ACCOUNT_GIFTCARDS_ID))); 
          ((GlobalVars) getActivity().getApplication()).setCardBalance(listBalance.get(position).get(TAG_ACCOUNT_GIFTCARDS_BALANCE)); 
         } else { 
          ((GlobalVars) getActivity().getApplication()).setIdBankAccount(0); 
          ((GlobalVars) getActivity().getApplication()).setIdGiftCard(0); 
          ((GlobalVars) getActivity().getApplication()).setCardBalance(listBalance.get(position).get(TAG_ACCOUNT_X111_BALANCE)); 
         } 

         ((BaseContainerFragment) getParentFragment()).replaceFragment(fragment, true); 
        } 

       }, anim.getDuration()); 
      } 
      // Item is not the first, so trade places with first one 
      else { 
       HashMap<String, String> tmp = listBalance.get(0); 
       Log.d(TAG, tmp.toString()); 

       listBalance.set(0, listBalance.get(position)); 
       listBalance.set(position, tmp); 
       adapter.notifyDataSetChanged(); 
       updateAdapter(); 
      } 
     } 
    }); 

彈跳動畫

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android"> 

    <scale 
     android:duration="50" 
     android:fromXScale="1.0" 
     android:fromYScale="1.0" 
     android:pivotX="50%" 
     android:pivotY="50%" 
     android:toXScale="1.1" 
     android:toYScale="1.1" /> 

    <scale 
     android:duration="50" 
     android:fromXScale="0.9" 
     android:fromYScale="0.9" 
     android:pivotX="50%" 
     android:pivotY="50%" 
     android:startOffset="50" 
     android:toXScale="1.0" 
     android:toYScale="1.0" /> 
</set> 

適配器

public View getView(final int position, View convertView, ViewGroup parent) { 
    vi = convertView; 

    if (layout == "account") { 

     if (convertView == null) { 
      vi = inflater.inflate(R.layout.activity_account_list_item, null); 
     } 

     TextView transaction_name = (TextView) vi.findViewById(R.id.account_name); 
     TextView transaction_address = (TextView) vi.findViewById(R.id.account_address); 
     TextView transaction_date = (TextView) vi.findViewById(R.id.account_date); 
     ImageView transaction_icon = (ImageView) vi.findViewById(R.id.account_image); 

     HashMap<String, String> transactions = new HashMap<String, String>(); 
     transactions = data.get(position); 

     // Setting all values in listview 
     transaction_name.setText(transactions.get(FragmentCardBalance.TAG_ACCOUNT_TRANSACTIONS_NAME)); 
     transaction_address.setText(transactions.get(FragmentCardBalance.TAG_ACCOUNT_TRANSACTIONS_ADDRESS)); 
     transaction_date.setText(transactions.get(FragmentCardBalance.TAG_ACCOUNT_TRANSACTIONS_DATE)); 
     imageLoader.DisplayImage(transactions.get(FragmentCardBalance.TAG_ACCOUNT_TRANSACTIONS_ICON), transaction_icon); 
    } 

    else if (layout == "balance") { 
     String[] color = { "56a77a","568fa7" ,"f8d243", "8fb63c", "114783", "e1ac47", "58ACFA", "819FF7", "5858FA", 
       "AC58FA", "FE9A2E", "FA5858", "FA5882"}; 
     //Log.d("COLOR", "Color: " + color[position] + " | Position: " +position); 
     if (convertView == null && position == 0) { 
      vi = inflater.inflate(R.layout.activity_cardholder_list_item_first, null); 

      TextView saldo = (TextView) vi.findViewById(R.id.tvSaldo); 
      TextView balance_idBankAccount = (TextView) vi.findViewById(R.id.idBankAccount); 
      TextView balance_idGiftCard = (TextView) vi.findViewById(R.id.idGiftCard); 
      TextView balance_amount = (TextView) vi.findViewById(R.id.tvAmount); 
      TextView balance_cardNumber = (TextView) vi.findViewById(R.id.tvCardNumber); 
      TextView balance_expDate = (TextView) vi.findViewById(R.id.tvExpDate); 
      ImageView balance_foto = (ImageView) vi.findViewById(R.id.ivLogo); 
      LinearLayout background = (LinearLayout) vi.findViewById(R.id.background); 
      GradientDrawable bgShape = (GradientDrawable)background.getBackground(); 

      HashMap<String, String> balance = new HashMap<String, String>(); 
      balance = data.get(position); 

      // Setting all values in listview 
      balance_idBankAccount.setText(balance.get(FragmentCardHolder.TAG_ACCOUNT_BANKACCOUNTS_ID)); 
      balance_idGiftCard.setText(balance.get(FragmentCardHolder.TAG_ACCOUNT_GIFTCARDS_ID)); 
      if(balance.get(FragmentCardHolder.TAG_ACCOUNT_X111_BALANCE) == null){ 
       if(balance.get(FragmentCardHolder.TAG_ACCOUNT_BANKACCOUNTS_TYPE).equals("1")){ 
        balance_amount.setText("CREDITO"); 
       } else { 
        balance_amount.setText("DEBITO"); 
       } 
       String card = balance.get(FragmentCardHolder.TAG_ACCOUNT_BANKACCOUNTS_CARDNUMBER); 
       card = "**** **** **** " + card.substring(card.length() - 4, card.length()); 
       balance_cardNumber.setText(card); 
       if (saldo != null) { 
        saldo.setText(""); 
       } 
      } else { 
       balance_amount.setText("$ " + balance.get(FragmentCardHolder.TAG_ACCOUNT_X111_BALANCE)); 
       balance_expDate.setText(""); 
       balance_cardNumber.setText(""); 
      } 
      imageLoader.DisplayImage(balance.get(FragmentCardHolder.TAG_ACCOUNT_BANKACCOUNTS_FOTO), balance_foto); 


      bgShape.setColor(Color.GREEN); 

      if(color != null){ 
       bgShape.setColor(Integer.parseInt(color[position], 16) + 0xFF000000); 
      } 
     } 
     // set layout for the next items 
     else if (convertView == null && position != 0) { 
      vi = inflater.inflate(R.layout.activity_cardholder_list_item, null); 

      TextView saldo = (TextView) vi.findViewById(R.id.tvSaldo); 
      TextView balance_idBankAccount = (TextView) vi.findViewById(R.id.idBankAccount); 
      TextView balance_idGiftCard = (TextView) vi.findViewById(R.id.idGiftCard); 
      TextView balance_amount = (TextView) vi.findViewById(R.id.tvAmount); 
      ImageView balance_foto = (ImageView) vi.findViewById(R.id.ivLogo); 
      LinearLayout background = (LinearLayout) vi.findViewById(R.id.background); 
      GradientDrawable bgShape = (GradientDrawable)background.getBackground(); 

      HashMap<String, String> balance = new HashMap<String, String>(); 
      balance = data.get(position); 

      // Setting all values in listview 
      balance_idBankAccount.setText(balance.get(FragmentCardHolder.TAG_ACCOUNT_BANKACCOUNTS_ID)); 
      balance_idGiftCard.setText(balance.get(FragmentCardHolder.TAG_ACCOUNT_GIFTCARDS_ID)); 

      if(balance.get(FragmentCardHolder.TAG_ACCOUNT_X111_BALANCE) == null){ 
       if(balance.get(FragmentCardHolder.TAG_ACCOUNT_BANKACCOUNTS_TYPE).equals("1")){ 
        balance_amount.setText("CREDITO"); 
       } else { 
        balance_amount.setText("DEBITO"); 
       } 
       saldo.setText(""); 
      } else { 
       balance_amount.setText("$ " + balance.get(FragmentCardHolder.TAG_ACCOUNT_X111_BALANCE)); 
      } 
      imageLoader.DisplayImage(balance.get(FragmentCardHolder.TAG_ACCOUNT_BANKACCOUNTS_FOTO), balance_foto); 

      if(color[position] != null){ 
       bgShape.setColor(Integer.parseInt(color[position], 16) + 0xFF000000); 
      } 
     } 
    } 
} 
+0

爲什麼不使用一個可膨脹的ListView?它會爲你節省一些麻煩。 –

1

如果我是你,我會使用類似的可擴展列表視圖,這是在android庫中的一種列表視圖的東西。

基本上,您需要對listview進行以下更改,以使其像您發佈的關於iOS的視頻一樣工作。

  1. 將所選項目移動到可擴展列表視圖中的第一個位置後,一旦它被選定。
  2. 編碼一個DialogActivity,一旦再次選擇該項目,它將顯示細節。

一個可膨脹的ListView的工作示例可以在鏈接中可以看出here

希望這有助於:)

相關問題