Ghosting Effect: Two Views On Top Of Each Other. Why?
I want to be able to click on buttons to navigate forward and backward through several views as well as swiping left or right between views. So I decided to implement the ViewPage
Solution 1:
Change
@OverridepublicbooleanisViewFromObject(View parent, Objectobject) {
return parent== ((View) object);
}
to
@OverridepublicbooleanisViewFromObject(View v, Object o) {
return parent == object;
}
Update:
After watching your movie your problem is you put some static wedget on the top of your viewpager, so remove that, which means your layout will become something like this:
This is your main_activity.xml
you must assign it to your activity
by function setContentView
<?xml version="1.0" encoding="utf-8"?><RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"android:background="@color/white"
><android.support.v4.view.ViewPagerxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:id="@+id/viewPager"/></RelativeLayout>
then at instantiateItem
use below layout:
Baca Juga
- Attempt To Invoke Virtual Method 'void Android.support.v4.view.viewpager.setadapter(android.support.v4.view.pageradapter)' On A Null Object Reference
- How Exactly Does Jvm Compile Ternary Operators? Should I Be Concerned About Different Api Versions?
- Pass Data To Another Fragment By Swipe View With Tab Android Studio,not Button
<?xml version="1.0" encoding="utf-8"?><RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"android:background="@color/white"
><ImageViewandroid:id="@+id/apple"android:layout_width="200sp"android:layout_height="150sp"android:layout_centerHorizontal="true"android:layout_centerVertical="true"android:src="@drawable/apple"android:contentDescription="apple"/><TextViewandroid:id="@+id/number"android:layout_width="100sp"android:layout_height="55sp"android:layout_marginTop="47dp"android:layout_below="@+id/apple"android:layout_alignStart="@+id/apple"/><Buttonandroid:id="@+id/save"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/save"android:layout_alignTop="@+id/ignore"android:layout_toStartOf="@+id/apple"/><Buttonandroid:id="@+id/ignore"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/Ignore"android:layout_alignParentBottom="true"android:layout_toEndOf="@+id/apple"/><ImageViewandroid:id="@+id/back_nav_arrow"android:layout_width="wrap_content"android:layout_height="wrap_content"android:src="@drawable/ic_action_back"android:contentDescription="back"></ImageView><ImageViewandroid:id="@+id/forward_nav_arrow"android:layout_width="wrap_content"android:layout_height="wrap_content"android:src="@drawable/ic_action_forward"android:layout_alignParentTop="true"android:layout_alignParentEnd="true"android:contentDescription="forward"></ImageView>
your main activity:
protectedvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setContentView(R.layout.collection);
viewPager = (ViewPager) findViewById(R.id.viewPager);
myAdapter = newMyAdapter();
viewPager.setAdapter(myAdapter);
ActionBaractionBar= getActionBar();
if (actionBar != null) {
actionBar.hide();
}
//Attach the page change listener inside the activity
viewPager.setOnPageChangeListener(newViewPager.OnPageChangeListener() {
// This method will be invoked when the current page is scrolled@OverridepublicvoidonPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
//This method will be invoked when a new page becomes selected@OverridepublicvoidonPageSelected(int position) {
//get position
currentPage = position;
}
// Called when the scroll state changes:// SCROLL_STATE_IDLE, SCROLL_STATE_DRAGGING, SCROLL_STATE_SETTLING@OverridepublicvoidonPageScrollStateChanged(int i) {
//get state
}
});
}
then assign your click listener of your main activity at this function
@Overridepublic Object instantiateItem(ViewGroup parent, int position) {
Viewview= LayoutInflater.from(parent.getContext()).inflate(R.layout.collection, parent, false);
ImageViewimageView= (ImageView) view
.findViewById(R.id.apple);
imageView.setImageResource(R.drawable.apple);
finalImageViewback_button= (ImageView) view.findViewById(R.id.back_nav_arrow);
back_button.setOnClickListener(newView.OnClickListener() {
publicvoidonClick(View view) {
//it doesn't matter if you're already in the first item
viewPager.setCurrentItem(viewPager.getCurrentItem() - 1);
}
});
parent.addView(view,0);
return view;
}
Post a Comment for "Ghosting Effect: Two Views On Top Of Each Other. Why?"