2013-03-01 9 views
6

GridLayoutを水平方向にスクロールするのに問題があります。GridLayoutのAndroid、水平および垂直スクロール

私は同様の質問を見つけましたGridlayout + ScrollView。私はその方法を試みたが、うまくいかなかった。

(1から20までのすべてのテーブルを表示するはずだったので)多くのテーブルを削除します。ここで

は、xmlファイル

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" > 

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

     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal" 
      android:padding="16dp" > 

      <android.support.v7.widget.GridLayout 
       android:id="@+id/table_mapGrid" 
       android:layout_width="250dp" 
       android:layout_height="wrap_content" /> 
     </LinearLayout> 
    </ScrollView> 

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

    <TextView 
     android:id="@+id/table_errorView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_vertical" 
     android:layout_marginLeft="20dp" 
     android:text="@string/message_error_connection" 
     android:visibility="invisible" /> 

</FrameLayout> 

である私は、動的なコンテンツを持つようにしたいテーブル間の空のスペースで、おそらく列数と行数を変化させ、表示されました。 これは成し遂げましたが、GridLayoutの幅がコンテナの幅より大きくなり、水平スクロールを使って解決したいと思っていましたが、動作しないようです...

何か提案がありますか?

答えて

9

まあ、私はアンドロイドScrollViewがVerticalScrollViewとして動作し、(名前はHorizo​​ntalScrollViewほど直感的ではない)だけというように思えソリューションに

を見つけました。

だから、垂直方向と水平方向のスクロール可能なものを作るために、あなたが巣にHorizo​​ntalScrollView内部(垂直)ScrollView、または周りに他の方法を必要とする、この

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 
    <HorizontalScrollView 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent"> 

      <!-- Your content here --> 

    </HorizontalScrollView> 
</ScrollView> 
+0

はアンドロイドでprogrameticalyそれを行うにはとにかくありますか? –

+0

はい、上記と同じ内容をプログラムで作成するだけです。 mScrollView.addView(mHorizo​​ntalScrollView); mHorizo​​ntalScrollView.addView(yourContentHere); –

1

のように入れ子にHorizo​​ntalScrollView/ScrollViewはあなたを許しません同時に両方向にスクロールします。 が、私はこの問題を抱えていたし、そのためのカスタムコンポーネントを作成し、それは誰を助けることができるならば、ここでのリンクは次のとおりです。

https://gist.github.com/androidseb/9902093

関連する問題