Help us understand the problem. What is going on with this article?

Android Studio TabbedActivity 拡張

各フラグメント表示後、上からリストビューが下りてくるTabbedActivityです。
ポイントはSectionsPagerAdapter#setPrimaryItem()でリストビューのY位置変更処理をする所です。
下記のコードの大部分はTabbedActivity を選択すると、AndroidStudio が自動的に生成してくれます。

サンプル動画(YouTube)

    public static class PlaceholderFragment extends Fragment {

        private static final String ARG_SECTION_NUMBER = "section_number";
        static ListView[] list = new ListView[7];  //リストビュー変数宣言

        public PlaceholderFragment() {
        }

        public static PlaceholderFragment newInstance(int sectionNumber) {
            PlaceholderFragment fragment = new PlaceholderFragment();
            Bundle args = new Bundle();
            args.putInt(ARG_SECTION_NUMBER, sectionNumber);
            fragment.setArguments(args);
            return fragment;
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_stage_select, container, false);
            int selector = getArguments().getInt(ARG_SECTION_NUMBER);

///////////////////////////////////////////////ここから追加
            ImageView imageView = rootView.findViewById(R.id.imageView);
            list[selector] = rootView.findViewById(R.id.movingList);
            ArrayList messages = new ArrayList<String>();
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(this.getActivity(), android.R.layout.simple_list_item_1, messages);
            list[selector].setAdapter(adapter);

            switch(selector){
                case 0:
                    messages.add("Stage0");
                    messages.add("Level1");
                    break;
                case 1:
                    messages.add("Stage1");
                    break;
                case 2:
                    messages.add("Stage2");
                    list[2].setY(-list[2].getHeight());
                    break;
                case 3:
                    messages.add("Stage3");
                    messages.add("Level 250");
                    //imageView.setImageResource(R.drawable.stage3);
                    break;
                case 4:
                    messages.add("Level 2 室町用");
                    imageView.setImageResource(R.drawable.stage4);
                    break;
                case 5:
                    messages.add("How to play");
                    messages.add("Level 0");
                    imageView.setImageResource(R.drawable.stage5);
                    break;
                case 6:
                    messages.add("Stage6");
                    //imageView.setImageResource(R.drawable.stage6);
                    break;
            }
///////////////////////////////////////////////ここまで追加
            return rootView;
        }

    }

    public class SectionsPagerAdapter extends FragmentPagerAdapter {
        int page;

        public SectionsPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return PlaceholderFragment.newInstance(position);
        }

        @Override
        public int getCount() {
            return 7;  //要素数設定
        }

///////////////////////////////////////ここから追加
        @Override
        public void setPrimaryItem(ViewGroup container, final int position, Object object){
            super.setPrimaryItem(container, position, object);
            if(page == position)return;
            final float hide_y = -PlaceholderFragment.list[position].getHeight();

            //前ページのList隠し処理
            for(int i = 0; i < 7; i++){
                if(PlaceholderFragment.list[i] != null)
                PlaceholderFragment.list[i].setY(-PlaceholderFragment.list[i].getHeight());
            }

            page = position;

            new Thread(new Runnable(){
                float y = hide_y;
                public void run(){
                    while(y < 0) {
                        ListView list = PlaceholderFragment.list[position];
                        list.setY(y);
                        Log.d("messaged", "position y: " + y);
                        y += 5;  //Y軸移動量 / 1ステップ
                        try {
                            Thread.sleep(10);  //タイムインターバル
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }
            }).start();
            Log.d("messaged", "setPrimaryItem    position: " + position);
        }
////////////////////////////////////////////ここまで追加
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away