gpt4 book ai didi

java - 如何在特定的 ViewPager 页面隐藏 View ?请查看详情

转载 作者:行者123 更新时间:2023-11-30 01:42:41 25 4
gpt4 key购买 nike

ImageView 实际上是一个右箭头。我用它来浏览 ViewPager 的页面。

我想要的是在导航到 ViewPager 的最后(第 6 个)页面后立即隐藏此 ImageView(向右箭头)/strong>.

这是我到目前为止为完成它所做的工作:

protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_walkthroughs);
// Create the adapter that will return a fragment for each of the three
// primary sections of the activity.
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.container);
mViewPager.setAdapter(mSectionsPagerAdapter);

ImageView imageView = (ImageView) findViewById(R.id.right_arrow);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mViewPager.setCurrentItem(mViewPager.getCurrentItem() + 1);
}
});

**here is my code**
if (mViewPager.getCurrentItem() == 6) {
imageView.setVisibility(View.GONE);
}

}

这是activity_walkthroughs.xml文件代码:

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical">

<android.support.design.widget.CoordinatorLayout
android:id="@+id/main_content"
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"
android:fitsSystemWindows="true"
tools:context="com.abc.xyz.Walkthroughs">

<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"/>

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

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/colorPrimary">

<View
android:layout_width="1dp"
android:layout_height="@dimen/viewpagerindicator_height"
android:background="@android:color/white"
android:layout_alignParentTop="true"
android:layout_alignLeft="@+id/right_arrow"
android:layout_alignStart="@+id/right_arrow"/>

<ImageView
android:id="@+id/right_arrow"
android:layout_width="wrap_content"
android:layout_height="@dimen/viewpagerindicator_height"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:background="@drawable/btn_touch_feedback_impression"
android:src="@drawable/ic_action_right_arrow"/>

</RelativeLayout>

</RelativeLayout>

问题是这段代码没有完成任务。

请告诉我问题出在哪里!

提前致谢。

最佳答案

谢谢 NigamPatro .

你的回答给了我找到正确方法的线索。

这是我在 mViewPager.addOnPageChangeListener() 中所做的:

mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

}

@Override
public void onPageSelected(int position) {
switch (position) {
case 0:
imageView.setVisibility(View.VISIBLE);
break;
case 1:
imageView.setVisibility(View.VISIBLE);
break;
case 2:
imageView.setVisibility(View.VISIBLE);
break;
case 3:
imageView.setVisibility(View.VISIBLE);
break;
case 4:
imageView.setVisibility(View.VISIBLE);
break;
case 5:
imageView.setVisibility(View.INVISIBLE);
break;
default:
imageView.setVisibility(View.VISIBLE);
break;
}
}

@Override
public void onPageScrollStateChanged(int state) {

}
});

不过这很容易。

和平。

关于java - 如何在特定的 ViewPager 页面隐藏 View ?请查看详情,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34224193/

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