我把這個Pager Sliding Tab Strip。我得到的輸出,因爲它是。傳呼機滑動標籤條與按鈕和編輯文本適當的選項卡
但我唯一的問題是我不知道如何添加類別按鈕選項卡,Textview for Home選項卡,Edittext爲Top Paid選項卡。
在那裏,我看到的只有兩個佈局:
activity_main.xml中:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.astuetz.PagerSlidingTabStrip
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="48dip"
android:background="@drawable/background_tabs" />
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/colors"
android:layout_below="@+id/tabs"
tools:context=".MainActivity" />
<LinearLayout
android:id="@+id/colors"
android:layout_width="match_parent"
android:layout_height="48dip"
android:layout_alignParentBottom="true"
android:layout_marginBottom="8dip"
android:layout_marginLeft="4dip"
android:layout_marginRight="4dip"
android:orientation="horizontal" >
</LinearLayout>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/colors"
android:layout_alignTop="@+id/pager"
android:layout_marginLeft="58dp"
android:layout_marginTop="46dp"
android:text="Button" />
</RelativeLayout>
fragment_quick_contact.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="170dip"
android:scaleType="centerCrop"
android:src="@drawable/contact" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/image"
android:background="#77000000"
android:paddingBottom="14dip"
android:paddingLeft="8dip"
android:paddingTop="14dip"
android:text="Quick Contact"
android:textColor="#FFFFFFFF"
android:textSize="18sp" />
<com.astuetz.PagerSlidingTabStrip
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="62dip"
android:layout_below="@+id/image"
android:background="@drawable/background_tabs_diagonal"
app:pstsDividerColor="#00000000"
app:pstsIndicatorColor="#FF33B5E6"
app:pstsTabPaddingLeftRight="14dip"
app:pstsUnderlineColor="#FF33B5E6" />
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="96dip"
android:layout_below="@+id/tabs" />
</RelativeLayout>
MainActivity,JAVA:
public class MyPagerAdapter extends FragmentPagerAdapter {
private final String[] TITLES = { "Categories", "Home","Profile" };
public MyPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public CharSequence getPageTitle(int position) {
return TITLES[position];
}
@Override
public int getCount() {
return TITLES.length;
}
return SuperAwesomeCardFragment.newInstance(position);
}
}
如果我在activity_main.xml中添加一個按鈕。它只是添加按鈕不僅在類別選項卡。但是,它在所有選項卡中添加按鈕。
我需要在類別選項卡中添加按鈕。然後我必須在主頁tab.is中添加編輯文本,這可以在Pager Sliding Tab Strip中執行此操作。
編輯:沒有分別爲類別選項卡和主頁選項卡的xml佈局。這就是爲什麼我對此感到困惑。
你怎麼加按鈕的位置?在activity_main.xml佈局上的 ?或在viewpager的片段? – calvinfly
@calvinfly我被編輯了我的activity_main.xml。我將它添加到了activity_main.xml.check中。 – Steve
你應該添加按鈕類別選項卡片段,而不是activity_main佈局 – calvinfly