2

javaコードとそのxmlとスクリーンショットを添付しています。 tablayout.javaはtablaout.xmlを添付するクラスで、画面の下部にtablayoutを配置すると、レイアウトの上部にあるスペースの一部が無駄になります。レイアウトの最後にタブレイアウトを整列しているときに、レイアウトの上部にスペースが残っています

TabLayout.java

public class Bottom_Tabs_Activity extends AppCompatActivity { 
    private TabLayout tabLayout; 
    private ViewPager viewPager; 
    private int[] tabIcons = { 
      R.drawable.ic_friends, 
      R.drawable.ic_map, 
      R.drawable.ic_status, 
      R.drawable.ic_chat, 
      R.drawable.ic_profile 
    }; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.tabs); 
     viewPager = (ViewPager) findViewById(R.id.viewpager); 
     if (viewPager != null) 
      setupViewPager(viewPager); 
     else { 
      Log.e("test", "i am null"); 
     } 
     tabLayout = (TabLayout) findViewById(R.id.tabs); 
     tabLayout.setupWithViewPager(viewPager); 

     setupTabIcons(); 
    } 
     private void setupTabIcons() { 
      tabLayout.getTabAt(0).setIcon(tabIcons[0]); 
      tabLayout.getTabAt(1).setIcon(tabIcons[1]); 
      tabLayout.getTabAt(2).setIcon(tabIcons[2]); 
      tabLayout.getTabAt(3).setIcon(tabIcons[3]); 
      tabLayout.getTabAt(4).setIcon(tabIcons[4]); 
     } 

    private void setupViewPager(ViewPager viewPager) 
    { 
     ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager()); 
     adapter.addFrag(new MapFragment(),"MAPS"); 
     adapter.addFrag(new PeopleFragment(),"PEOPLE"); 
     adapter.addFrag(new HomeFragment(),"HOME"); 
     adapter.addFrag(new ChatFragment(),"CHAT"); 
     adapter.addFrag(new ProfileFragment(),"PROFILE"); 

     viewPager.setAdapter(adapter); 
    } 
    class ViewPagerAdapter extends FragmentPagerAdapter 
    { 
     private final List<Fragment> mFragmentList = new ArrayList<>(); 
     private final List<String> mFragmentTitleList = new ArrayList<>(); 
     public ViewPagerAdapter(FragmentManager manager) 
     { 
      super(manager); 
     } 
     @Override 
     public Fragment getItem(int position) { 
      return mFragmentList.get(position); 
     } 
     @Override 
     public int getCount() { 
      return mFragmentList.size(); 
     } 
     public void addFrag(Fragment fragment, String title) { 
      mFragmentList.add(fragment); 
      mFragmentTitleList.add(title); 
     } 
     @Override 
     public CharSequence getPageTitle(int position) { 

      // return null to display only the icon 
      return null; 
     } 
    } 
} 

tablayout.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/main_content" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/appbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
     android:gravity="bottom" 
     android:layout_gravity="bottom"> 

     <android.support.design.widget.TabLayout 
      android:id="@+id/tabs" 
      app:tabMode="fixed" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="#000000" 
      app:tabIndicatorColor="#ff1232" 
      app:tabGravity="fill" 
      /> 

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

    <android.support.v4.view.ViewPager 
     android:id="@+id/viewpager" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 

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

スクリーンショット enter image description here

答えて

2

空きがあなたのアクションバーで、あなたはそれを別のレイアウトを提供し、添付する必要がありますそのレイアウトに必要な地図と人物。 このコードを下に書くと、あなたのアクティビティのコンテンツビューが表示され、必要に応じて編集できます。

getSupportActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.black))); 
     getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); 
     getSupportActionBar().setCustomView(R.layout.action_bar); 

     EditText s= (EditText) getSupportActionBar().getCustomView().findViewById(R.id.centertext2); 
     s.setText("New Role"); 

それとも、アクションバーを削除したい場合は

getSupportActionBar().hide(); 

が、これはあなたのお役に立てば幸いです。

+0

メソッドgetcolorは廃止されました。代わりに使用するものです。 –

関連する問題