툴바와 호환되는 Android에서 내비게이션 탭을 만들려고합니다. https : /github.com/codepath/android_guides/wiki/Google-Play-Style-Tabs-using-SlidingTabLayout의 튜토리얼을 사용 합니다. 잠시 후 UI를 표시하고 탐색 탭이 표시되고 문제는 조각 인 각 탭의 내용이 표시되지 않는다는 것입니다. 오류를 유발하지 않습니다.
class SamplePagerAdapter extends FragmentPagerAdapter {
private String tabTitles[] = new String[] {"Tab One", "Tab Two"};
private Context context;
public SamplePagerAdapter(FragmentManager fm, Context context) {
super(fm);
this.context = context;
}
@Override
public int getCount() {
return tabTitles.length;
}
@Override
public CharSequence getPageTitle(int position) {
return tabTitles[position];
}
@Override
public Fragment getItem(int position) {
if(position == 0) {
return new TabOneFragment();
} else if(position == 1) {
return new TabTwoFragment();
}
return null;
}
}
TabActivity
public class TabActivity extends ActionBarActivity {
private SlidingTabLayout mSlidingTabLayout;
private ViewPager mViewPager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cards);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
mViewPager = (ViewPager) findViewById(R.id.viewpager);
mViewPager.setAdapter(new SamplePagerAdapter(getSupportFragmentManager(), this));
mSlidingTabLayout = (SlidingTabLayout) findViewById(R.id.sliding_tabs);
mSlidingTabLayout.setDistributeEvenly(true);
mSlidingTabLayout.setViewPager(mViewPager);
}
}
activity_tab.xml
<RelativeLayout
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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".TabActivity">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize" />
<com.example.android.view.SlidingTabLayout
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/toolbar" />
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1"
android:background="@android:color/white"/>
</RelativeLayout>
TabOneFragment.java
public class PromoFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_tab_one, container, false);
}
}
fragment_tab_one.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" tools:context=".TabOneFragment">
<TextView android:layout_width="match_parent" android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:gravity="center"
android:id="@+id/text"
android:text="@string/hello_blank_fragment"
android:textSize="100sp" />
</FrameLayout>
TabOne Fragment UI :
표시되는 내용 :
여기에 버그가 있습니다
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1"
android:background="@android:color/white"/>
이것으로 변경 ..
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/sliding_tabs"
android:background="@android:color/white"/>
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다