2015-09-23 181 views
0

我正在開發Android的ImageView的Horizo​​ntalScrollView的片段。我想實現一個垂直的ScrollView作爲父節點和Horizo​​ntalScrollView作爲它的子節點。我怎樣才能實現這個?這裏是我的Horizo​​ntalScrollView .xml文件: -水平滾動視圖內垂直滾動查看

<!-- TODO: Update blank fragment layout --> 
<SearchView 
    android:layout_width="fill_parent" 
    android:layout_height="40dp" 
    android:id="@+id/searchView" 
    android:focusable="true" 
    android:textStyle = "bold|italic" 
    android:queryHint="@string/search" 
    android:clickable="true" 
    android:background="#ffffff" /> 

<HorizontalScrollView 
    android:layout_width="match_parent" 
    android:layout_height="200dp" 
    android:scrollbars="horizontal" 
    android:id="@+id/horizontalScrollView"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     style="@style/LoginFormContainer" 
     android:orientation="horizontal"> 

     <ImageView 
      android:layout_width="300dp" 
      android:layout_height="200dp" 
      android:layout_marginRight="2dp" 
      android:src="@drawable/picture1" /> 

     <ImageView 
      android:layout_width="300dp" 
      android:layout_height="200dp" 
      android:layout_marginLeft="2dp" 
      android:layout_marginRight="2dp" 
      android:src="@drawable/picture2" /> 

     <ImageView 
      android:layout_width="300dp" 
      android:layout_height="200dp" 
      android:layout_marginLeft="2dp" 
      android:layout_marginRight="2dp" 
      android:src="@drawable/picture3" /> 

     <ImageView 
      android:layout_width="300dp" 
      android:layout_height="200dp" 
      android:layout_marginLeft="2dp" 
      android:layout_marginRight="2dp" 
      android:src="@drawable/picture6" /> 

     <ImageView 
      android:layout_width="300dp" 
      android:layout_height="200dp" 
      android:layout_marginLeft="2dp" 
      android:layout_marginRight="2dp" 
      android:src="@drawable/hospital" /> 

     <ImageView 
      android:layout_width="300dp" 
      android:layout_height="200dp" 
      android:layout_marginLeft="2dp" 
      android:src="@drawable/picture7" /> 

    </LinearLayout> 
</HorizontalScrollView> 

回答

0

ScrollView類是垂直滾動這樣:

<SearchView 
.../> 
    <ScrollView 
    .../> 
     <HorizontalScrollView 
     .../> 
      <LinearLayout 
      .../> 
       <!-- Multiple views here --> 
      </LinearLayout> 
     </HorizontalScrollView> 
    </ScrollView> 
</SearchView> 
+0

並假設如果我在界面上添加一些textViews那麼您提供的想法不起作用,因爲scrollView無法託管多個子視圖。你有解決這個問題嗎? –

+0

@AyushGupta我編輯了我的答案,就像在代碼中一樣使用'LinearLayout'。 – Sander