2016-08-27 14 views
1

here the image i want like thisこの基本的な質問を申し訳ありません。Googleで検索しますが解決策はありません。私はAndroidを初めて使っています。 Playストアのようなタブ下の横スクロールボタンいずれかを設計したいここに私のタブコードプレイステーションのようなタブの下に水平スクロールボタンを作成する方法android

を、これは私のレイアウトの下にここに

事前にあなたを.thank

<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

私はrecylerviewだけでなく、ボタンについて尋ねています、私は指摘image一度確認してください。[email protected] –

+0

http://stackoverflow.com/questions/31194199/how-to-enable-horizo​​ntal-scroll-in-tab-like-google-playこのリンクを見る..... ...質問とfuctionalityのデモを使用して –

答えて

0
  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(); 
     } 
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); 
} 
+0

私は横のスクロールボタンについてのみ私のコードを見てください私は私のポストを編集してくださいお願いしていますU @ Saurabh Bhardwaj –

+0

これらのタブをスクロールすることができますありがとうございます。 –

+0

はい私のタブはスクロールしています。私はプレイストアのように、タブの下に横スクロールボタンが必要です。@Saurabh Bhardwaj –

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> 
関連する問題