Я пытаюсь создать фрагмент, смахивая вниз. Я использую Viewpager, но я могу смахивать только вправо или влево, мне нужно что-то похожее на то, что делает Snapchat. Они используют фрагменты, но к ним можно получить доступ, проведя пальцем в любом направлении (вверх вниз , справа или слева), вот код, который я сейчас использую, он отлично работает, чтобы делать типичные движения фрагментов (вправо и влево), но мне нужно добавить что-то, что позволяет мне получить доступ к фрагменту, проведя пальцем вниз.
import ...
public class MainActivity extends AppCompatActivity {
/**
* The {@link android.support.v4.view.PagerAdapter} that will provide
* fragments for each of the sections. We use a
* {@link FragmentPagerAdapter} derivative, which will keep every
* loaded fragment in memory. If this becomes too memory intensive, it
* may be best to switch to a
* {@link android.support.v4.app.FragmentStatePagerAdapter}.
*/
private SectionsPagerAdapter mSectionsPagerAdapter;
/**
* The {@link ViewPager} that will host the section contents.
*/
private ViewPager mViewPager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// FullScreen
getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
// 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);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
/**
* The fragment argument representing the section number for this
* fragment.
*/
public PlaceholderFragment() {
}
/**
* Returns a new instance of this fragment for the given section
* number.
*/
public static PlaceholderFragment newInstance(int sectionNumber) {
PlaceholderFragment fragment = new PlaceholderFragment();
Bundle args = new Bundle();
fragment.setArguments(args);
return fragment;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.activity_main, container, false);
return rootView;
}
}
/**
* A {@link FragmentPagerAdapter} that returns a fragment corresponding to
* one of the sections/tabs/pages.
*/
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
Fragment fragment = null;
switch (position) {
case 0:
fragment = new RegisterLogin();
break;
case 1:
fragment = new PrincipalPage();
break;
case 2:
fragment = new DevsArea();
break;
}
return fragment;
}
@Override
public int getCount() {
// Show 3 total pages.
return 3;
}
}
}
а вот XML:
<?xml version = "1.0" encoding = "utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:id = "@+id/main_content"
android:layout_width = "match_parent"
android:layout_height = "match_parent"
android:fitsSystemWindows = "true"
tools:context = "com.vs.versus.versus.MainActivity">
<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>




посмотрите RecyclerView здесь https://developer.android.com/guide/topics/ui/layout/recyclerview.html
установите ориентацию RecyclerView на VERTICAL и сделайте корневой макет элемента View, используя height = "match_parent"
последний шаг, внедрите SnapHelper или используйте LinearSnapHelper напрямую и примените его к RecyclerView
вот SnapHelperhttps://developer.android.com/reference/android/support/v7/widget/SnapHelper.html
теперь у вас есть вертикальный ViewPager, ну что-то вроде этого.
Или просто используйте какой-нибудь другой проект (ы) для парней.
https://github.com/kaelaela/VerticalViewPager
https://github.com/chadguo/VerticalViewPager
Если вам нужен полный свайп в 4 направлениях (влево, вправо, вверх, вниз), оберните вертикальный RecyclerView в горизонтальный ViewPager.
Надеюсь, это то, что вы ищете. Если нет, скажите, пожалуйста
Я думаю, что RecyclerView может помочь мне в решении проблемы, заключающейся в том, что я не знаю, как поместить действие в RecyclerView.
Установите recyclerciew в качестве макета для вашей деятельности
Как я могу это сделать? в XML моей деятельности или в java-файле активности?
Я смущен, потому что не знаю, как реализовать Recycler в моем окне просмотра, это моя проблема
в XML для макета страницы ViewPager. о, ладно, подробности см. здесь stackoverflow.com/questions/30171692/recyclerviews-in-viewpa ger, или погуглите, там много информации и как что делать
Спасибо, я попробую????