0

FrameLayoutおよびTextViewは、ScrollViewに配置しても表示されません。 ViewPagerおよびFrameLayoutは、異なるandroid.support.v4.app.Fragmentgmentsに置き換えられています。 ViewPagerの末尾にFrameLayoutTextViewが表示されます(画面の高さを超えるとスクロールした後)。viewPagerの最後に兄弟ビューを表示するにはどうすればよいですか?

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 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:orientation="vertical"> 

    <include 
     layout="@layout/layout_appbar" /> 

    <ScrollView 
     android:layout_height="match_parent" 
     android:fillViewport="true" 
     android:layout_width="match_parent"> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:orientation="vertical" 
      android:layout_height="wrap_content"> 

      <android.support.v4.view.ViewPager 
       android:id="@+id/view_pager" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" /> 

      <FrameLayout 
       android:layout_width="match_parent" 
       android:id="@+id/view_container" 
       android:layout_height="wrap_content"/> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="8dp" 
       android:layout_gravity="center_horizontal" 
       android:text="@string/app_name"/> 
     </LinearLayout> 
    </ScrollView> 
</LinearLayout> 
+0

'ViewPager'の下部に永続的なビューを表示したい場合は、' ViewPager'の中に 'android:layout_above =" @ + id/bottomView' xml属性を追加し、 'android:layout_alignParentBottom = – Sabeeh

+0

上記の解決策では、 'viewPager'が下のビューの上にスクロールしていますが、スクロール後に' viewPager'の最後に下のビューを表示したいのですが、 –

+0

あなたの答えは、私がそれを追加させてください。 – Sabeeh

答えて

0

TLDR; 単にPagerAdaptergetItem()からこのフラグメントを返し、この断片のonViewCreated()のものFrameLayoutコンテナに子断片を追加し、Fragment内でこのレイアウトを膨らませる、レイアウト内ScrollViewFrameLayoutコンテナを追加します。


ふくらませる

R.layout.frag_mainあなたMainActivity/MainFragment、レイアウト次

<RelativeLayout android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:android="http://schemas.android.com/apk/res/android"> 

     <android.support.v4.view.ViewPager 
      android:id="@+id/view_pager" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"/> 

</RelativeLayout> 

セットアップいくつかのPagerAdapterViewPagerと、このようなアダプタのgetItem()方法から必要なフラグメントを返します

@Override 
    public Fragment getItem(int position) { 
     return ViewPagerFragment.newInstance(position); 
    } 

@Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
          Bundle savedInstanceState) { 
     View view = null; 
     int position = getArguments().getInt(ARG_POSITION); 
     switch (position) { 
      case 0: 
       view = inflater.inflate(R.layout.page_0, container, false); 
       break; 
      case 1: 
       view = ... //page 1 layout 
       break; 
      case 2: 
       view = ... //page 2 layout 
       break; 
     } 

     return view; 
    } 

    @Override 
    public void onViewCreated(View view, Bundle savedInstanceState) { 
     super.onViewCreated(view, savedInstanceState); 
     if (view.findViewById(R.id.view_container2) != null) { 
      getChildFragmentManager().beginTransaction() 
        .add(R.id.view_container, new FrameLayoutFragment()) 
        .commit(); 
     } 

    } 

内部

ViewPagerFragmentpositionでページのために、あなたは

R.layout.page_0を膨らませることができます。

<ScrollView 
    android:layout_height="match_parent" 
    android:fillViewport="true" 
    android:layout_width="match_parent"> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:orientation="vertical" 
     android:layout_height="wrap_content"> 

     <--your ViewPagerFragment content here--> 

     <FrameLayout 
      android:layout_width="match_parent" 
      android:id="@+id/view_container" 
      android:layout_height="wrap_content"/> 

    </LinearLayout> 
</ScrollView> 
あり

あなたはそれ

  1. ディを持っていますViewPagerFrameLayout
  2. FrameLayoutFragmentは、ViewPagerFragmentの末尾に追加されているため、スクロールして表示されます。
+0

これは私がしたい解決策ではありません。私は 'ViewPager'にアニメーションを追加しましたが、アニメーションのみにしたいのですが、とにかく私は上記のリンクで問題を解決しました。あなたのお手伝いをします。 –

関連する問題