gpt4 book ai didi

android - PagerSlidingTabStrip指示灯不随页面变化?

转载 作者:太空狗 更新时间:2023-10-29 14:57:12 24 4
gpt4 key购买 nike

它适用于我的搜索 Activity 页面,但不适用于我的个人资料 Activity :所选选项卡下的指示灯,我是否必须添加一些东西
这是代码:

public class ProfileActivity extends AppCompatActivity implements View.OnClickListener {

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

getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

String[] tabTitles = {"Completed", "Joined"};
adapter = new TabAdapter(getSupportFragmentManager(), profileCompletedFrag, profileJoinedFrag, tabTitles);

// // Initialize the ViewPager and set an adapter
pager = (ViewPager) findViewById(R.id.profilePager);
pager.setAdapter(adapter);

// Bind the tabs to the ViewPager
tabs = (PagerSlidingTabStrip) findViewById(R.id.profileTabs);
tabs.setViewPager(pager);

/**
* on swiping the viewpager make respective tab selected
* */
tabs.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

@Override
public void onPageSelected(int position) {
// on changing the page
if (position == 0) {
currentPage = 0;
pager.setCurrentItem(0);


}
if (position == 1) {
currentPage = 1;
pager.setCurrentItem(1);

}

}

@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
}

@Override
public void onPageScrollStateChanged(int arg0) {
}
});
/////////////
tabs.setOnTabReselectedListener(new PagerSlidingTabStrip.OnTabReselectedListener() {
@Override
public void onTabReselected(int position) {
Toast.makeText(ProfileActivity.this, "Tab reselected: " + position, Toast.LENGTH_SHORT).show();
if (position == 0) {
currentPage = 0;
pager.setCurrentItem(0);
}
if (position == 1) {
currentPage = 1;
pager.setCurrentItem(1);
}
}
});

他是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"
android:layout_width="match_parent" android:layout_height="match_parent"
android:id="@+id/profileParentLayout">
<LinearLayout
android:orientation="horizontal"
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/profileNameLayout"
android:layout_alignParentTop="true"
android:layout_marginTop="20dp"
android:layout_marginBottom="10dp">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/profileName"
android:layout_centerInParent="true"
android:text="Bob Marley"/>
</LinearLayout>


<RelativeLayout
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_marginBottom="10dp"
android:layout_centerHorizontal="true"
android:id="@+id/profileImageLayout"
android:layout_below="@+id/profileNameLayout">

<ImageView
android:layout_width="75dp"
android:layout_height="75dp"
android:id="@+id/profileImage"
android:src="@drawable/camera_w"
android:layout_centerInParent="true"/>
<ImageView android:id="@+id/editProfileImage"
android:layout_height="30dp"
android:layout_width="30dp"
android:src="@drawable/ic_launcher"
android:layout_alignParentRight="true"/>
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
android:layout_marginBottom="10dp"
android:id="@+id/profileDetailsLayout"
android:layout_below="@id/profileImageLayout">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/profileFollowers"
android:text="13 followers"
android:textSize="20dp"/>

<View android:id="@+id/separator"
android:layout_marginLeft="5dip"
android:background="#ffffff"
android:layout_width = "1dip"
android:layout_height="fill_parent"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/profileFollowing"
android:text="45 following"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:textSize="20dp"
/>

<View android:id="@+id/separator2"
android:layout_marginRight="5dip"
android:background="#ffffff"
android:layout_width = "1dip"
android:layout_height="fill_parent"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/profilePoints"
android:text="124 points"
android:textSize="20dp"/>
</LinearLayout>

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="?attr/actionBarSize"
android:orientation="horizontal"
android:id="@+id/tabsLayout"
android:layout_below="@+id/profileDetailsLayout">
<!-- for Tabs -->
<com.astuetz.PagerSlidingTabStrip
android:id="@+id/profileTabs"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:pstsShouldExpand="true"
android:background="?attr/colorPrimary"/>

<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/profilePager"
android:layout_width="match_parent"
android:layout_height="wrap_content">

</android.support.v4.view.ViewPager>
</LinearLayout>



<GridView
android:layout_below="@+id/tabsLayout"
android:id="@+id/profileGridView"
android:layout_marginTop="10dp"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:numColumns="auto_fit"
android:columnWidth="90dp"
android:horizontalSpacing="10dp"
android:verticalSpacing="10dp"
android:gravity="center"
android:stretchMode="columnWidth" >

</GridView>

</RelativeLayout>

最佳答案

 public class TabAdapter  extends FragmentStatePagerAdapter {

String[] tabTitles = {"Completed", "Joined"};

public TabAdapter(FragmentManager fragmentManager) {
// TODO Auto-generated constructor stub
super(fragmentManager);
}


@Override
public CharSequence getPageTitle(int position) {
// TODO Auto-generated method stub
return tabTitles[position];
}


@Override
public Fragment getItem(int arg0) {

switch (arg0) {
case 0:
return ProfileDataFagment.newInstance(0);
case 1:
return ProfileDataFagment.newInstance(1);
default:
break;
}

return null;

}

@Override
public int getCount() {
// TODO Auto-generated method stub
return 2; // Number of views
}


}

//同时创建 ProfileDataFagment 并根据你的位置设置你的数据

关于android - PagerSlidingTabStrip指示灯不随页面变化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30249115/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com