Défilement Vertical dans viewpager
J'ai un fragmentPagerAdapter viewpager
avec quelques fragment de classes à l'intérieur. Donc, ce viewpager
défile horizontalement à gauche et à droite avec le passage des doigts. Le truc c'est que sur chaque page de mes valeurs sont supérieures à la taille de la page et j'ai besoin de faire défiler verticalement les voir tous. Mais je ne peux pas activer l'une de défilement verticale. J'ai supprimé tout scrollview
s j'ai eu et j'ai obtenu mon code dans un état de fonctionnement. (Je veux quelque chose comme de l'app store Android: faire défiler horizontalement pour les catégories et verticalement pour afficher les applications.)
Voici mon code:
MyFragmentPagerAdapter:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:isScrollContainer="true">
<android.support.v4.view.PagerTitleStrip
android:id="@+id/pager_title_strip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:background="#33b5e5"
android:paddingBottom="4dp"
android:paddingTop="4dp"
android:textColor="#fff" />
</android.support.v4.view.ViewPager>
</RelativeLayout>
Le fragment activité qui doit le défilement vertical:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="30dp"
android:layout_marginTop="10dp"
android:text="Last fill-up spent :"
android:textSize="15dp" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:layout_marginTop="15dp"
android:text="Month total spent :"
android:textSize="15dp" />
<TextView
android:id="@+id/currentMoneySpentText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/textView2"
android:layout_marginLeft="24dp"
android:layout_toRightOf="@+id/textView1"
android:textSize="15dp" />
<TextView
android:id="@+id/monthTotalSpentText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/textView2"
android:layout_alignLeft="@+id/currentMoneySpentText"
android:textSize="15dp" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView2"
android:layout_below="@+id/textView2"
android:layout_marginTop="15dp"
android:text="Year total spent :"
android:textSize="15dp" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView3"
android:layout_below="@+id/textView3"
android:layout_marginTop="15dp"
android:text="Since 1st addition :"
android:textSize="15dp" />
<TextView
android:id="@+id/yearTotalSpentText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/textView4"
android:layout_alignLeft="@+id/monthTotalSpentText"
android:textSize="15dp" />
<TextView
android:id="@+id/firstTotalSpentText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/textView4"
android:layout_alignLeft="@+id/yearTotalSpentText"
android:textSize="15dp" />
<TextView
android:id="@+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView6"
android:layout_below="@+id/textView6"
android:layout_marginTop="1dp"
android:text="since last addition :"
android:textSize="15dp" />
<TextView
android:id="@+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView7"
android:layout_below="@+id/textView7"
android:layout_marginTop="15dp"
android:text="Distance covered"
android:textSize="15dp" />
</RelativeLayout>
Voici les premières lignes de mon fragment de classe, qui sont pertinents:
public class MyFragmentDetails extends Fragment {
private RelativeLayout ll;
private FragmentActivity fa;
DBAdapter db;
//MyFragmentFuel fFuels;
private String carSelected, m, y, lowestDistance, highestDistance;
BroadcastReceiver receiver;
int highestDay = 0;
int lowestDay = 31;
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
@SuppressWarnings("static-access")
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
fa = super.getActivity();
super.onCreate(savedInstanceState);
ll = (RelativeLayout) inflater.inflate(
R.layout.activity_add_fuel_details, container, false);
- stackoverflow.com/questions/8381697/... avez-vous essayer cela?
- j'ai vu ce code mais je ne sais pas où je devrais l'utiliser.
- vous utilisez ces code sur onStart()dans votre Fragment de classe qui est gonfler MyFragmentPagerAdapter mise en page.
- Je ne vois pas quel est ton problème. Ce n'est pas de travail? Mon problème est que si il y a du contenu qui est à défilement vertical, le mouvement de balayage à effet de swithc "page" dans le pager est perdu, que tout mouvement dans le sens vertical de "rejets", la traînée effet. Ainsi, lorsque u essayer de glisser à gauche/droite, vous échouent souvent parce que votre doigt ne bouge pas EXACTEMENT à l'horizontale.
Vous devez vous connecter pour publier un commentaire.
Créer une classe dans votre projet de mettre ce
}
en XML appel de cette classe au lieu de
android.support.v4.view.ViewPager
Après cela, si vous voulez faire un événement spécifique sur votre parchemin puis utiliser :
Cela est applicable, la version android de la guimauve et au-dessus:
Pour les versions antérieures, vous pouvez utiliser:
Essayer d'emballage le contenu dans un
NestedScrollView
. Si le défilement ne fonctionne toujours pas (ce n'était pas dans mon cas), essayez d'ajouter unOnTouchListener
que les appelsrequestDIsallowInterceptTouchEvent(true)
sur son parent si vous êtes de défilement vertical: