2016-06-12 5 views

答えて

2

ScrollViewおよびHorizontalScrollViewは、ユーザが垂直または水平にスクロールして物理ディスプレイよりも大きくできるようにするためのレイアウトコンテナです。 ScrollView/HorizontalScrollViewFrameLayoutです。つまり、スクロールする内容全体を含む1人の子供をその中に配置する必要があります。この子自体が、オブジェクトの複雑な階層を持つレイアウトマネージャである場合があります。詳細について

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

    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/hello" /> 

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

     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"> 

      <TextView 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="Inside 1st HorizontalScrollView" /> 

      <LinearLayout 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:orientation="horizontal"> 

       <Button 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Button A1" /> 

       <Button 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Button A2" /> 

       <Button 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Button A3" /> 

       <Button 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Button A4" /> 

       <Button 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Button A5" /> 
      </LinearLayout> 
     </LinearLayout> 
    </HorizontalScrollView> 

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

     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"> 

      <TextView 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="Inside 2nd HorizontalScrollView" /> 

      <LinearLayout 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:orientation="horizontal"> 

       <Button 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Button B1" /> 

       <Button 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Button B2" /> 

       <Button 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Button B3" /> 

       <Button 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Button B4" /> 

       <Button 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Button B5" /> 

       <Button 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Button B6" /> 
      </LinearLayout> 
     </LinearLayout> 
    </HorizontalScrollView> 

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

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:orientation="vertical"> 

      <TextView 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="Inside ScrollView" /> 

      <Button 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="Button C" /> 

      <Button 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="Button D" /> 

      <Button 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="Button E" /> 

      <Button 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="Button F" /> 

      <Button 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="Button G" /> 

      <Button 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="Button H" /> 

      <Button 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="Button I" /> 
     </LinearLayout> 
    </ScrollView> 
</LinearLayout> 

これを参照してください:http://android-coding.blogspot.in/2011/01/scrollview-and-horizontalscrollview.html

更新:

verticalなどhorizontalをスクロールするために、このXMLを使用する。ここ

は、XMLです。

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

     <HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="320px" android:layout_height="fill_parent"> 



     </HorizontalScrollView> 

    </ScrollView> 
+0

私が探していたもの、水平スクロールビューが存在するかどうかはわかりませんでした。ただ一つの簡単な質問:レイアウトをスクロール可能にし、同時に水平スクロール可能にする方法? Horizo​​ntalScrollViewをScrollViewの子として配置し、元のレイアウトをHorizo​​ntalScrollViewの子にするとうまくいくでしょうか? – Leonz

+0

@Leonzは 'Horizo​​ntalScrollView'を' ScrollView'の中に入れました。 – Ironman

+0

@Leonz私の更新の回答を見てください。 – Ironman

関連する問題