2017-10-08 1 views
0

리틀,하지만 성가신 문제가 작동하지 않습니다CoordinatorLayout match_parent는

내가 탭이 ListView를 포함하는 탭이있는 Activity을했습니다. 그러나 ViewPager의 크기를 match_parent으로 설정하면 모든 것이 잘 보일 것입니다. BUT, 하단에 ViewPager의 egde가 화면 밖으로 나옵니다. 이처럼

: link

결과 : link

레이아웃 :

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
              xmlns:tools="http://schemas.android.com/tools" 
              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:fitsSystemWindows="true" 
              tools:context="de.gymoth.goapp.vertretungsplan.VertretungsplanActivityNew"> 

<android.support.design.widget.AppBarLayout 
     android:id="@+id/appbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:paddingTop="@dimen/appbar_padding_top" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

    <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:popupTheme="@style/AppTheme.PopupOverlay" 
      app:layout_scrollFlags="scroll|enterAlways"> 

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

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

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

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

자바 :

public class VertretungsplanActivityNew extends AppCompatActivity { 

private VertretungsplanFragment firstFragment; 
private VertretungsplanFragment secondFragment; 
private TabLayout tabLayout; 

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

    firstFragment = VertretungsplanFragment.newInstance(0); 
    secondFragment = VertretungsplanFragment.newInstance(1); 

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
    setSupportActionBar(toolbar); 
    SectionsPagerAdapter sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); 

    ViewPager viewPager = (ViewPager) findViewById(R.id.container); 
    viewPager.setAdapter(sectionsPagerAdapter); 

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

public class SectionsPagerAdapter extends FragmentPagerAdapter { 

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

    @Override 
    public Fragment getItem(int position) { 
     switch(position) { 
      case 0: 
       return firstFragment; 
      case 1: 
       return secondFragment; 
      default: 
       return null; 
     } 
    } 

    @Override 
    public int getCount() { 
     return 2; 
    } 

    @Override 
    public CharSequence getPageTitle(int position) { 
     return ""; 
    } 
} 

public void setTabTitle(int index, CharSequence title) { 
    tabLayout.getTabAt(index).setText(title); 
} 
} 

누구에게도 설명이 있습니까? 도움을 주시면 감사하겠습니다.

답변

0

CoordinatorLayoutLinearLayout으로 바꾸면 정상적으로 작동합니다. 나는 샘플 코드를 추가했다.

<LinearLayout 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:orientation="vertical"> 

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

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:layout_scrollFlags="scroll|enterAlways" 
      app:popupTheme="@style/AppTheme.PopupOverlay"> 

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

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

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

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

감사합니다. – Tacoboy

+0

당신은 환영합니다! –

0

CoordinatorLayout의 기능이 필요하지 않으면 Roshan의 대답이 좋습니다. 그런 경우 간단한 해결 방법을 사용할 수 있습니다.

<android.support.v4.view.ViewPager 
    android:id="@+id/container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_marginBottom="48dp" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 
관련 문제