here the image i want like this对不起要问这个基本问题。我在谷歌搜索但没有解决方案,我是新手android我开发标签像最新的谷歌游戏商店我做了那部分但我想设计水平滚动按钮下面像Play商店这样的标签请帮我解决这个问题。提前谢谢你
这里是我的布局
<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>
这里是我的标签代码
@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);
}
}
答案 0 :(得分:0)
ctrl + v
答案 1 :(得分:0)
你可以试试这个......
@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);
}
答案 2 :(得分:0)
<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>