gpt4 book ai didi

java - Google Glass 全屏自定义布局卡

转载 作者:行者123 更新时间:2023-11-29 03:10:19 25 4
gpt4 key购买 nike

我有一个问题。由于 Card 类已弃用并且 CardBuilder.EMBED_INSIDE 相当有限。唯一的选择是使用自定义 View 。我还想使用 CardScrollView 和 CardScrollAdapter。

访问Google Glass Immersion Custom Layout without CardBuilder.Layout.EMBED_INSIDE

但我的问题是,我不能有多个 View 。

这是 MyCustomViewClass:

   public class MyCustomView extends FrameLayout{
public MyCustomView (Context context) {
super(context);
initView();
}

private void initView()
{
View view = inflate(getContext(), R.layout.imageview, null);
addView(view);

View view2 = inflate(getContext(), R.layout.secondview, null);
addView(view2);
}

那是我的主要 Activity 课:

public class InspectionActivity extends Activity {

private CardScrollView mCardScroller;
private GestureDetector mGestureDetector;
private View mView;
private CardScrollView _cardScroller;
private ArrayList<View> _cardsList;
private MyCustomView _myView;
protected List<CardBuilder> mCards;
@Override

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
createCards();
_cardsList = new ArrayList<View>();
_myView= new MyCustomView (this);
_cardsList.add(_myView);
_cardScroller = new CardScrollView(this) ;
MainCardsScrollAdapter adapter = new MainCardsScrollAdapter(_cardsList);
_cardScroller.setAdapter(adapter);
_cardScroller.activate();
setContentView(_cardScroller);
}

private void createCards() {
mCards = new ArrayList<CardBuilder>();
}
public class MainCardsScrollAdapter extends CardScrollAdapter
{
ArrayList<View> _cardsList;
public MainCardsScrollAdapter(ArrayList<View> cardsList)
{
_cardsList = cardsList;
}

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

@Override
public Object getItem(int i) {
return _cardsList.get(i);
}


@Override
public View getView(int i, View view, ViewGroup viewGroup) {
return _cardsList.get(i);
}

@Override
public int getPosition(Object o) {
return _cardsList.indexOf(o);
}

@Override
public int getViewTypeCount() {
return CardBuilder.getViewTypeCount();
}

@Override
public int getItemViewType(int position){
return 2;//should be changed, it's just an example
}
} }

最佳答案

好吧,从你的帖子来看,我猜它只是将你的一个布局膨胀到 CardScrollView 中。尝试以下操作。

  1. 创建一个看起来像这样的适配器类

    public class mainAdapter extends CardScrollAdapter {

    private List<CustomCard> mCards;
    private LayoutInflater inflater;

    public mainAdapter(List<CustomCard> cards, LayoutInflater inf)
    {
    this.mCards = cards;
    this.inflater = inf;
    }

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

    @Override
    public Object getItem(int i) {
    return mCards.get(i);
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
    int card = mCards.get(i).getLayout();
    view = inflater.inflate(card, viewGroup, false);
    return view;
    }

    @Override
    public int getPosition(Object o) {
    return this.mCards.indexOf(o);
    }
    }

我的 CustomCard 类看起来像这样,您可以只使用 List<Integer>相反

public class CustomCard {
public int getLayout() {
return layout;
}

public int layout;

public CustomCard(int layout)
{
this.layout = layout;
}
}
  1. 在您的 Activity 类中创建并填充一个包含所需布局的列表,然后将它们传递给您的适配器,如下所示。

onCreate()

CreateCards();
mCardScroller = new CardScrollView(this);
mCardScroller.setAdapter(new mainAdapter(mCards, getLayoutInflater()));

CreateCards()方法看起来像这样

public void CreateCards() {
mCards.add(new CustomCard(R.layout.firstview));
mCards.add(new CustomCard(R.layout.secondview));
mCards.add(new CustomCard(R.layout.thirdview));
}

希望对你有用

关于java - Google Glass 全屏自定义布局卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29729507/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com