菜鸟教程小白 发表于 2022-12-12 09:36:53

android - 将 iOS Controller 复制到 Android 中


                                            <p><p>我正在将 iOS 应用程序复制到 Android 中。该应用程序有一个带有信用卡动画的“钱包”屏幕,请参见下面的 iOS 应用程序视频。如何在 Android 中实现类似的功能?</p>

<p>这是 iOS 钱包的视频 -> <a href="https://www.youtube.com/watch?v=1sY4YkaQgu8" rel="noreferrer noopener nofollow">Wallet iOS demo</a> </p>

<p>我需要复制这些功能:</p>

<ol>
<li>选择卡片时带有动画的 ListView (当您单击卡片时,它会与新卡片切换位置)</li>
<li>点击主卡(大的)会产生弹跳动画并转到卡的详细信息。</li>
<li>在主卡上向左滑动也可以进入卡的详细信息。</li>
</ol>

<p>这是 iOS 中用于使其工作的库是 <a href="https://github.com/gleue/TGLStackedViewController" rel="noreferrer noopener nofollow">GLStackedViewController</a> .</p>

<p> <a href="/image/k22Z9.jpg" rel="noreferrer noopener nofollow"><img src="/image/k22Z9m.jpg" alt="Wallet" title="Click to enlarge"/></a> </p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>我最终从头开始制作,不需要库并使用常规 ListView。</p>

<p>在包含所有卡片的 cardHolderfragment 中,当单击第一项(0)时,卡片会弹跳,然后转到详细 fragment ,当单击不是第一个的其他项时,只需更改 ListView 顺序并更新适配器,这里缺少的一件事是点击之间的卡片动画,仍然是 WIP。 </p>

<pre><code>    // Click event for single list row
    list.setOnItemClickListener(new AdapterView.OnItemClickListener() {

      @Override
      public void onItemClick(AdapterView&lt;?&gt; parent, View view,
                              final int position, long id) {

            Log.d(TAG, &#34;Position: &#34; + 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(&#34;&#34;);
                        } 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&lt;String, String&gt; tmp = listBalance.get(0);
                Log.d(TAG, tmp.toString());

                listBalance.set(0, listBalance.get(position));
                listBalance.set(position, tmp);
                adapter.notifyDataSetChanged();
                updateAdapter();
            }
      }
    });
</code></pre>

<p>弹跳动画</p>

<pre><code>&lt;?xml version=&#34;1.0&#34; encoding=&#34;utf-8&#34;?&gt;
&lt;set xmlns:android=&#34;http://schemas.android.com/apk/res/android&#34;&gt;

    &lt;scale
      android:duration=&#34;50&#34;
      android:fromXScale=&#34;1.0&#34;
      android:fromYScale=&#34;1.0&#34;
      android:pivotX=&#34;50%&#34;
      android:pivotY=&#34;50%&#34;
      android:toXScale=&#34;1.1&#34;
      android:toYScale=&#34;1.1&#34; /&gt;

    &lt;scale
      android:duration=&#34;50&#34;
      android:fromXScale=&#34;0.9&#34;
      android:fromYScale=&#34;0.9&#34;
      android:pivotX=&#34;50%&#34;
      android:pivotY=&#34;50%&#34;
      android:startOffset=&#34;50&#34;
      android:toXScale=&#34;1.0&#34;
      android:toYScale=&#34;1.0&#34; /&gt;
&lt;/set&gt;
</code></pre>

<p>适配器</p>

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

    if (layout == &#34;account&#34;) {

      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&lt;String, String&gt; transactions = new HashMap&lt;String, String&gt;();
      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 == &#34;balance&#34;) {
      String[] color = { &#34;56a77a&#34;,&#34;568fa7&#34; ,&#34;f8d243&#34;, &#34;8fb63c&#34;, &#34;114783&#34;, &#34;e1ac47&#34;, &#34;58ACFA&#34;, &#34;819FF7&#34;, &#34;5858FA&#34;,
                &#34;AC58FA&#34;, &#34;FE9A2E&#34;, &#34;FA5858&#34;, &#34;FA5882&#34;};
      //Log.d(&#34;COLOR&#34;, &#34;Color: &#34; + color + &#34; | Position: &#34; +position);
      if (convertView == null &amp;&amp; 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&lt;String, String&gt; balance = new HashMap&lt;String, String&gt;();
            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(&#34;1&#34;)){
                  balance_amount.setText(&#34;CREDITO&#34;);
                } else {
                  balance_amount.setText(&#34;DEBITO&#34;);
                }
                String card = balance.get(FragmentCardHolder.TAG_ACCOUNT_BANKACCOUNTS_CARDNUMBER);
                card = &#34;**** **** **** &#34; + card.substring(card.length() - 4, card.length());
                balance_cardNumber.setText(card);
                if (saldo != null) {
                  saldo.setText(&#34;&#34;);
                }
            } else {
                balance_amount.setText(&#34;$ &#34; + balance.get(FragmentCardHolder.TAG_ACCOUNT_X111_BALANCE));
                balance_expDate.setText(&#34;&#34;);
                balance_cardNumber.setText(&#34;&#34;);
            }
            imageLoader.DisplayImage(balance.get(FragmentCardHolder.TAG_ACCOUNT_BANKACCOUNTS_FOTO), balance_foto);


            bgShape.setColor(Color.GREEN);

            if(color != null){
                bgShape.setColor(Integer.parseInt(color, 16) + 0xFF000000);
            }
      }
      // set layout for the next items
      else if (convertView == null &amp;&amp; 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&lt;String, String&gt; balance = new HashMap&lt;String, String&gt;();
            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(&#34;1&#34;)){
                  balance_amount.setText(&#34;CREDITO&#34;);
                } else {
                  balance_amount.setText(&#34;DEBITO&#34;);
                }
                saldo.setText(&#34;&#34;);
            } else {
                balance_amount.setText(&#34;$ &#34; + balance.get(FragmentCardHolder.TAG_ACCOUNT_X111_BALANCE));
            }
            imageLoader.DisplayImage(balance.get(FragmentCardHolder.TAG_ACCOUNT_BANKACCOUNTS_FOTO), balance_foto);

            if(color != null){
                bgShape.setColor(Integer.parseInt(color, 16) + 0xFF000000);
            }
      }
    }
}
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于android - 将 iOSController 复制到 Android 中,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/33426118/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/33426118/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: android - 将 iOS Controller 复制到 Android 中