查看寻呼机和信用卡视图

时间:2016-10-07 23:51:35

标签: android android-layout android-viewpager android-designer

我有一个用于查看信用卡的viewPager。在此viewPager中,使用TextViews放置了一个带有卡片图像和属性的imageView。我还没有意识到信用卡设计git(https://github.com/sharish/CreditCardView)并开始使用它。但是当我尝试设置属性时,它属于默认值而不是箭头属性。 (它与文本视图一起正常工作)。我正在使用卡片列表,他建议用我拥有的卡片查看寻呼机但不设置值(所有创建的卡片都相同),也就是说,它不会把它放在列表中。我做对了吗?

  

PagerView.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:layout_below="@+id/pager"
    android:layout_centerHorizontal="true"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
   >

    <com.cooltechworks.creditcarddesign.CreditCardView
        android:id="@+id/card_5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:card_expiration="01/17"
        />


</RelativeLayout>
  

AdapterCard.java

public class AdapterCards extends android.support.v4.view.PagerAdapter {
    Context context;
    private List<Card> listCards = new ArrayList<>();

    public AdapterCards(Context context, List<Card> listCards){
        this.context = context;
        this.listCards = listCards;
    }

    @Override
    public int getCount() {
        return listCards.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view==object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position){
        LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View itemView = layoutInflater.inflate(R.layout.pagecards, container, false);

        CreditCardView creditCardView = new CreditCardView(context);
        creditCardView.setCardExpiry(listCards.get(position).cardValid);

        container.addView(itemView);

        return itemView;


    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object view){
        container.removeView((View)view);
    }
}

0 个答案:

没有答案