4 중주 게임을 프로그래밍하므로 각 카드의 모든 속성을 포함하는 갤러리가 필요합니다. 대신 모든 레이아웃 PARAMS을 정의하는 (예를 들어, 내 게임 활동의) http://android-er.blogspot.de/2014/04/example-of-viewpager-with-custom.html사용자 정의 PageAdapter가있는 ViewPager, Java에서 레이아웃을 정의하는 대신 XML 파일을 사용하는 방법
이 꽤 좋은 간단한 갤러리보기를 들어,하지만 난 XML 파일을 포함 할 것이다 : 나는 사용자 정의 PagerAdapter와 ViewPager의 예를 발견 명시 적으로. 어떤 아이디어 주셔서 감사합니다! 여기
내 어댑터 클래스 :
이private class MyPagerAdapter extends PagerAdapter {
int numberOfPages = cards.size();
int[] backgroundcolor = {
0xFF101010};
@Override
public int getCount() {
return numberOfPages;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
//select Card on current position from List of cards
final Card tempCard = cards.get(position);
//set TextView with deck title
TextView textView = new TextView(DeckViewActivity.this);
textView.setTextColor(Color.WHITE);
textView.setTextSize(30);
textView.setTypeface(Typeface.DEFAULT_BOLD);
textView.setText(tempCard.getTitle() + " (" + String.valueOf(position + 1) + "/" + cards.size() + ")");
//set ImageView with deckcover
ImageView imageView = new ImageView(DeckViewActivity.this);
ViewGroup.LayoutParams imageParams = new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
imageView.setLayoutParams(imageParams);
int finalHeight = viewPager.getMeasuredHeight();
int finalWidth = viewPager.getMeasuredWidth();
//Load Bitmap from assets
InputStream inputStream = null;
try {
inputStream = getAssets().open(tempCard.getPicture());
imageView.setImageBitmap(decodeSampledBitmapFromResource(inputStream, finalWidth, finalHeight));
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
//imageView.setImageResource(res[position]);
LinearLayout layout = new LinearLayout(DeckViewActivity.this);
layout.setOrientation(LinearLayout.VERTICAL);
ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
layout.setBackgroundColor(backgroundcolor[0]);
layout.setLayoutParams(layoutParams);
layout.addView(textView);
layout.addView(imageView);
final int page = position;
layout.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
}});
container.addView(layout);
return layout;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((LinearLayout)object);
}
}
감사합니다. 'instantiateItem()'에서 저에게 잘 작동합니다 : View view = getLayoutInflater(). inflate (R.layout.page_viewer_pie, container, false);' – goemic