2017-06-21 12 views
0

私はいくつかのページを持っています。これは画面よりも大きなコンテンツ、つまりユーザーがさらに多くのコンテンツを見るためにスクロールしなければなりません。これらのページはViewPager内にあります。私の人生のために、私は垂直スクロールの仕事をする方法を把握することができません。ViewPagerで垂直方向にスクロールしてページングを水平方向に行う

私は別のページに垂直方向にスクロールするだけで、1ページ内をスクロールする必要はありません。

私は誰かが正しい方向に私を向けることを望んでいます。検索で何も得られませんが、これは一般的なことではない場合は驚くでしょうか?

  1. を表示するポケットベルや他のビューを保持しているリニアレイアウトの周りにscrollviewをラップ:私が試した何

  2. レイアウトとレイアウトパラメータの異なる組み合わせ。提案を1として

おかげ

、私は私のフラグメントのXMLは以下の通りですので、それが画面に収まらないという十分なコンテンツを持っている、AndroidHiveから例を撮影しました。だから、リストビューと同様にスクロールして残りのコンテンツを見ることができると思うだろう。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<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="wrap_content" 
    tools:context="info.androidhive.materialtabs.fragments.OneFragment"> 

    <TextView 
     android:id="@+id/text" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/one" 
     android:textSize="40dp" 
     android:textStyle="bold" /> 

    <TextView 
     android:id="@+id/text1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/text" 
     android:text="@string/one" 
     android:textSize="40dp" 
     android:textStyle="bold" /> 

    <TextView 
     android:id="@+id/text2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/text1" 
     android:text="@string/one" 
     android:textSize="40dp" 
     android:textStyle="bold" /> 

    <TextView 
     android:id="@+id/text3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/text2" 
     android:text="@string/one" 
     android:textSize="40dp" 
     android:textStyle="bold" /> 

    <TextView 
     android:id="@+id/text4" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/text3" 
     android:text="@string/one" 
     android:textSize="40dp" 
     android:textStyle="bold" /> 

    <TextView 
     android:id="@+id/text5" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/text4" 
     android:text="@string/one" 
     android:textSize="40dp" 
     android:textStyle="bold" /> 

    <TextView 
     android:id="@+id/text6" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/text5" 
     android:text="@string/one" 
     android:textSize="40dp" 
     android:textStyle="bold" /> 

    <TextView 
     android:id="@+id/text7" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/text6" 
     android:text="@string/one" 
     android:textSize="40dp" 
     android:textStyle="bold" /> 

    <TextView 
     android:id="@+id/text8" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/text7" 
     android:text="@string/one" 
     android:textSize="40dp" 
     android:textStyle="bold" /> 

    <TextView 
     android:id="@+id/text9" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/text8" 
     android:text="@string/one" 
     android:textSize="40dp" 
     android:textStyle="bold" /> 

    <TextView 
     android:id="@+id/text10" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/text9" 
     android:text="@string/one" 
     android:textSize="40dp" 
     android:textStyle="bold" /> 
</RelativeLayout> 
</ScrollView> 

私はサンプルコードから何も変更していません。

+0

Scrollviewタグが閉じていません。 –

+0

誤ってコピーされています。実際には正しく閉じられています。 – WolfBane

+0

相対レイアウトは、ビューグループを互いに対して配置します。 テキストを別のテキストビューの左側に配置することができます あなたの例では、単純な解決策は代わりに線形レイアウトを使用することです。そのため、各テキストビューは互いに下に配置されています。 [続きを読む](http:// androidexample。com/Relative_Layout_Basics _-_ Android_Example/index.php?view = article_discription&aid = 73) –

答えて

2

ビューページ内のフラグメントをScrollviewで使用してください。

フラグメントは、垂直方向を提供するフラグメント内の望ましい水平ページングとスクロールビューを提供する必要があります。断片の一つ

<ScrollView 
     android:layout_width="fill_parent" 
     android:layout_height="match_parent"> 

<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" 
    tools:context="info.androidhive.materialtabs.fragments.OneFragment"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/one" 
     android:textSize="40dp" 
     android:textStyle="bold" 
     android:layout_centerInParent="true"/> 

</RelativeLayout> 
</ScrollView> 

Androidhiveため

断片の一つ

import android.os.Bundle; 
import android.support.v4.app.Fragment; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 

public class OneFragment extends Fragment{ 


public OneFragment() { 
    // Required empty public constructor 
} 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
} 

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 
    // Inflate the layout for this fragment 
    return inflater.inflate(R.layout.fragment_one, container, false); 
} 
} 

レイアウトが簡単なチュートリアルを持っているhttp://www.androidhive.info/2015/09/android-material-design-working-with-tabs/

+0

ありがとうございます。私はNestedScrollViewとCoordinaterViewを使用してこれを動作させることができました。 – WolfBane

0

フラグメントを試しましたか?スクロールビュー内のページレイアウトで、別のフラグメントのXMLファイルを作成します...

<!-- fragment_layout.xml --> 
<ScrollView 
    android:layout_width='match_parent' 
    android:layout_height='match_parent' 
    ...> 
    <WhateverYourPageLayoutIs 
     android:layout_width='match_parent' 
     android:layout_height='wrap_content' 
     .../> 
</ScrollView> 

そして、このレイアウトを使用してフラグメントのサブクラスを作成し、ビューのページャを移入するFragmentPagerAdapter(またはFragmentStatePagerAdapter)を使用します。

関連する問題