简体   繁体   English

如何在playstore android之类的标签下创建水平滚动按钮

[英]How to create horizontal scroll buttons below tabs like playstore android

here the image i want like this sorry for asking this basic question .I search in google but no solution , i'm new to android i develop tabs like latest google play store i did that part but i want design horizontal scroll button below the tab like play store any one please help me how to do this .thank you in advance 在这里,我想要这样的图像抱歉这个基本问题。我在谷歌搜索但没有解决方案,我是新手android我开发标签像最新的谷歌游戏商店我做了那部分,但我想在标签下面设计水平滚动按钮喜欢玩店任何一个请帮我怎么做。谢谢你提前

here below my layout 在我的布局下面

<android.support.design.widget.CoordinatorLayout
    android:id="@+id/coordinator"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
            app:statusBarScrim="?attr/colorPrimary"
            app:toolbarId="@+id/toolbar">

            <ImageView
                android:id="@+id/iv_header"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:scaleType="centerCrop"
                android:src="@drawable/music"
                app:layout_collapseMode="parallax"
                bind:height_aspect_ratio="@{4f/3}"/>

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="48dp"
                android:background="@android:color/transparent"
                android:theme="@style/AppTheme.AppBarOverlay"
                app:layout_collapseMode="pin"
                >

            </android.support.v7.widget.Toolbar>

            <com.chanti.engapp.widget.SearchBoxCompat
                android:id="@+id/search_box"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:layout_collapseMode="pin"/>

        </android.support.design.widget.CollapsingToolbarLayout>

        <android.support.design.widget.TabLayout
            android:id="@+id/tabLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="-48dp"
            android:background="@android:color/transparent"
            android:foreground="@android:color/transparent"
            android:theme="@style/ThemeOverlay.AppCompat.Dark"
            app:layout_collapseMode="pin"
            app:layout_scrollFlags="scroll|enterAlways"
            app:tabBackground="@android:color/transparent"
            app:tabMode="scrollable"/>

    </android.support.design.widget.AppBarLayout>

    <include
        android:id="@+id/current_item"
        layout="@layout/fragment_item_tab"/>

</android.support.design.widget.CoordinatorLayout>

here my tabs code 这里我的标签代码

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.tabs_layout, container, false);
    ButterKnife.bind(this, view);
    swipeRefreshLayout = (SwipeRefreshLayout)view.findViewById(R.id.swipeRefreshLayout);
    mLayoutManager = new LinearLayoutManager(getActivity());
    LVRecentlyViewed.setLayoutManager(mLayoutManager);

    // specify an adapter (see also next example)
    contentList.clear();
    objects = ResultFragment.categoryDtoList.get(ResultFragment.viewPager.getCurrentItem()).getSubCategoryList();

    if (ResultFragment.adapter.getPageTitle(ResultFragment.viewPager.getCurrentItem()).equals("FilmNews")) {
        ResultFragment.IVImage.setImageResource(R.drawable.film);
    } else if (ResultFragment.adapter.getPageTitle(ResultFragment.viewPager.getCurrentItem()).equals("Videos")) {
        ResultFragment.IVImage.setImageResource(R.drawable.video);
    } else if (ResultFragment.adapter.getPageTitle(ResultFragment.viewPager.getCurrentItem()).equals("Music")) {
        ResultFragment.IVImage.setImageResource(R.drawable.music);
    } else {
        ResultFragment.IVImage.setImageResource(R.drawable.film);
    }

    getContentList();

    mAdapter = new RecentlyViewedListAdapter(getActivity(), R.layout.card_item2, contentList);

    LVRecentlyViewed.setAdapter(mAdapter);
    mAdapter.notifyDataSetChanged();
    //date sorting in onstart







    RecyclerItemClickSupport.addTo(LVRecentlyViewed).setOnItemClickListener(new RecyclerItemClickSupport.OnItemClickListener() {
        @Override
        public void onItemClicked(RecyclerView recyclerView, int position, View v) {
            chosenItem = contentList.get(position);
            if (!pageTitle.toString().equals("Movies")) {
                Intent intent = new Intent(getActivity(), DetailsVideosAndMusicActivity.class);
                Bundle bundle = new Bundle();
                bundle.putSerializable("choseItem", chosenItem);
                intent.putExtra("title",""+ResultFragment.viewPager.getCurrentItem());
                intent.putExtras(bundle);
                startActivity(intent);
            } else {
                Intent intent = new Intent(getActivity(), DetailsMovesActivity.class);

                startActivity(intent);
            }
        }
    });

    swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            request();
        }
    });
    return view;
}
private void request() {
    final ProgressDialog progressDialog = new ProgressDialog(getActivity());
    progressDialog.setMessage("Processing");
    progressDialog.show();
    ChantiApplication.getService().retrieveList().enqueue(new Callback<List<CategoryDto>>() {
        @Override
        public void onResponse(Call<List<CategoryDto>> call, Response<List<CategoryDto>> response) {
            swipeRefreshLayout.setRefreshing(false);
            progressDialog.hide();
            if (response.isSuccessful()) {
                contentList.clear();
                ResultFragment.categoryDtoList = response.body();
                objects = ResultFragment.categoryDtoList.get(ResultFragment.viewPager.getCurrentItem()).getSubCategoryList();

                if (ResultFragment.adapter.getPageTitle(ResultFragment.viewPager.getCurrentItem()).equals("FilmNews")) {
                    ResultFragment.IVImage.setImageResource(R.drawable.film);
                } else if (ResultFragment.adapter.getPageTitle(ResultFragment.viewPager.getCurrentItem()).equals("Videos")) {
                    ResultFragment.IVImage.setImageResource(R.drawable.video);
                } else if (ResultFragment.adapter.getPageTitle(ResultFragment.viewPager.getCurrentItem()).equals("Music")) {
                    ResultFragment.IVImage.setImageResource(R.drawable.music);
                } else {
                    ResultFragment.IVImage.setImageResource(R.drawable.film);
                }

                getContentList();

                mAdapter = new RecentlyViewedListAdapter(getActivity(), R.layout.card_item2, contentList);
                LVRecentlyViewed.setAdapter(mAdapter);

                mAdapter.notifyDataSetChanged();

            } else {
                ResponseDto error = ErrorUtils.parseError(response);
                Toast.makeText(getActivity(), error.getError(), Toast.LENGTH_SHORT).show();
            }
        }

        @Override
        public void onFailure(Call<List<CategoryDto>> call, Throwable t) {
            //  Log.d("error", t.getMessage());
        }
    });
}
@Override
public void onStart() {
    super.onStart();

    mLayoutManager = new LinearLayoutManager(getActivity());
    LVRecentlyViewed.setLayoutManager(mLayoutManager);

    // specify an adapter (see also next example)
    contentList.clear();
    objects = ResultFragment.categoryDtoList.get(ResultFragment.viewPager.getCurrentItem()).getSubCategoryList();

    if (ResultFragment.adapter.getPageTitle(ResultFragment.viewPager.getCurrentItem()).equals("FilmNews")) {
        ResultFragment.IVImage.setImageResource(R.drawable.film);
    } else if (ResultFragment.adapter.getPageTitle(ResultFragment.viewPager.getCurrentItem()).equals("Videos")) {
        ResultFragment.IVImage.setImageResource(R.drawable.video);
    } else if (ResultFragment.adapter.getPageTitle(ResultFragment.viewPager.getCurrentItem()).equals("Music")) {
        ResultFragment.IVImage.setImageResource(R.drawable.music);
    } else {
        ResultFragment.IVImage.setImageResource(R.drawable.film);
    }

    getContentList();

    mAdapter = new RecentlyViewedListAdapter(getActivity(), R.layout.card_item2, contentList);
    LVRecentlyViewed.setAdapter(mAdapter);

    mAdapter.notifyDataSetChanged();

    //date sorting in onstart

    Collections.sort(contentList, new Comparator<SubCategory>() {

        public int compare(SubCategory o1, SubCategory o2) {
            if (o1.getCreateDate() == null || o2.getCreateDate() == null)
                return 0;
            return o2.getCreateDate().compareTo(o1.getCreateDate());
        }
    });

}

private void getContentList()
{

    contentList.clear();
    pageTitle = ResultFragment.adapter.getPageTitle(ResultFragment.viewPager.getCurrentItem());
    ArrayList<String> checkedSubCat = CheckListActivity.checkedSubCateg.get(pageTitle);
    if (checkedSubCat != null) {
        for (String subCategoryName : checkedSubCat) {
            for (SubCategory object : objects) {
                if (subCategoryName.equals(object.getSubCategoryName())) {
                    for (SubCategory contentItem : object.getContentList()) {
                        contentList.add(contentItem);
                    }
                }
            }
        }
    } else {
        SharedPreferences preferences = getActivity().getSharedPreferences("Checked",0);
        Gson gson = new Gson();
        String json = preferences.getString("checkedSubCategory", "");
        if(json!=null) {
            CategoryListDto categoryListDto = gson.fromJson(json, CategoryListDto.class);
            if(categoryListDto!=null) {
                ArrayList<String> checkedCategory = categoryListDto.getCheckedSubCateg().get(pageTitle);
                for (String subCategoryName : checkedCategory) {
                    for (SubCategory object : objects) {
                        if (subCategoryName.equals(object.getSubCategoryName())) {
                            for (SubCategory contentItem : object.getContentList()) {
                                contentList.add(contentItem);
                            }
                        }
                    }
                }
            }
        }
    }
    Collections.sort(contentList, new Comparator<SubCategory>() {
        public int compare(SubCategory o1, SubCategory o2) {
            if (o1.getCreateDate() == null || o2.getCreateDate() == null)
                return 0;
            return o2.getCreateDate().compareTo(o1.getCreateDate());
        }
    });

}

public void getChoosenItem(int position) {
    chosenItem = contentList.get(position);
}

} }

           try {

            int height, width;
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
            LinearLayout subslytlnr = new LinearLayout(getActivity());
            subslytlnr.setLayoutParams(params);
            subslytlnr.setPadding(0, 12, 0, 12);
            HorizontalScrollView scrollViewSubscribeBtn;
            scrollViewSubscribeBtn = new HorizontalScrollView(getActivity());
            scrollViewSubscribeBtn.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
            scrollViewSubscribeBtn.setBackgroundResource(R.drawable.actionbartop);
            subsButton = new Button[numOf Buttons];

            for (int i = 0; i < numOf Buttons; i++) {

                LinearLayout.LayoutParams paramsBtn;
                width = (int) (getResources().getDimension(R.dimen.subsbuttonheight) / getResources().getDisplayMetrics().density);
                height = (int) (getResources().getDimension(R.dimen.subsbuttonwidth) / getResources().getDisplayMetrics().density);

                    paramsBtn = new LinearLayout.LayoutParams(100, 40);
                    paramsBtn.setMargins(10, 0, 10, 0);


                subsButton[i] = new Button(getActivity());

               subsButton[i].setTextSize(20);

                subsButton[i].setLayoutParams(paramsBtn);

                subsButton[i].setText("button"+i+"");
                subsButton[i].setBackgroundResource(R.drawable.border);
                subslytlnr.addView(subsButton[i]);
                subsButton[i].setOnClickListener(myClickListener3);
            }
            scrollViewSubscribeBtn.addView(subslytlnr);
            subsaBtnLayout.addView(scrollViewSubscribeBtn);
        } catch (Exception e) {
            e.printStackTrace();
        }

you can try this... 你可以尝试这个......

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_scrollable_tabs);

    viewPager = (ViewPager) findViewById(R.id.viewpager);
        setupViewPager2(viewPager);
        tabLayout = (TabLayout) findViewById(R.id.tabs);
        tabLayout.setupWithViewPager(viewPager);
    }

private void setupViewPager(ViewPager viewPager) {
    ViewPagerAdapter adapter = new            ViewPagerAdapter(getSupportFragmentManager());
    adapter.addFrag(new feature_fragment(), "Feature");
    adapter.addFrag(new service_fragment(), "Service");
    adapter.addFrag(new contact_fragment(), "Contact");
    adapter.addFrag(new login_fragment(), "Login");
    adapter.addFrag(new about_fragment(), "About");
    adapter.addFrag(new casi_certification_fragment(), "CASI Certification");

    viewPager.setAdapter(adapter);
}
      <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:background="#fff">

        <HorizontalScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="abc"
                    android:background="#ff0000" />
                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="abc"
                    android:textColor="#000"
                    android:background="#00ff00"
                 />
                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="abc"
                    android:background="#ff0000" />
                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="abc"
                    android:textColor="#000"
                    android:background="#00ff00"
                    />
                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="abc"
                    android:background="#ff0000" />
                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="abc"
                    android:textColor="#000"
                    android:background="#00ff00"
                    />
            </LinearLayout>

        </HorizontalScrollView>

    </RelativeLayout>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM