带有按钮的寻呼机滑动标签条和适当标签的编辑文本
Pager Sliding Tab Strip with Buttons and Edit Text for appropriate tab
我引用了这个 Pager Sliding Tab Strip。我得到的是原样的输出。
但我唯一的问题是我不知道如何为类别选项卡添加按钮,为主页选项卡添加 Textview,为热门付费选项卡添加 Edittext。
那里我只看到了两个布局:
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.But 中添加了按钮,还在所有选项卡中添加了按钮。
我需要在类别中添加按钮 tab.Then 我必须在主页中添加编辑文本 tab.is 可以在 Pager Sliding Tab Strip 中执行此操作。
编辑: 类别选项卡和主页没有单独的 xml 布局 tab.That 这就是我对此感到困惑的原因。
您应该在类别选项卡片段布局上添加按钮,而不是 activity_main 布局
用户@Calvinfly 推荐了我,所以我可以发现 answer.To 更清楚:
在我的MainActivity.java里面MyPagerAdapter
我设置的位置是这样的
@Override
public Fragment getItem(int position) {
switch (position) {
case 0:
return new Category();
case 1:
return new Home();
case 2:
return new TopPaid();
}
return SuperAwesomeCardFragment.newInstance(position);
}
我引用了这个 Pager Sliding Tab Strip。我得到的是原样的输出。
但我唯一的问题是我不知道如何为类别选项卡添加按钮,为主页选项卡添加 Textview,为热门付费选项卡添加 Edittext。
那里我只看到了两个布局:
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.But 中添加了按钮,还在所有选项卡中添加了按钮。
我需要在类别中添加按钮 tab.Then 我必须在主页中添加编辑文本 tab.is 可以在 Pager Sliding Tab Strip 中执行此操作。
编辑: 类别选项卡和主页没有单独的 xml 布局 tab.That 这就是我对此感到困惑的原因。
您应该在类别选项卡片段布局上添加按钮,而不是 activity_main 布局
用户@Calvinfly 推荐了我,所以我可以发现 answer.To 更清楚:
在我的MainActivity.java里面MyPagerAdapter
我设置的位置是这样的
@Override
public Fragment getItem(int position) {
switch (position) {
case 0:
return new Category();
case 1:
return new Home();
case 2:
return new TopPaid();
}
return SuperAwesomeCardFragment.newInstance(position);
}