2015-10-15 40 views
4

在我的android应用程序页面中,我使用滑块,textview和gridview来显示图像。现在问题是,当我向上滚动时,只有gridview图像滚动,其余部分保持静态。请帮助我如何让页面的所有内容随着滚动而移动?如何使android页面中的所有内容都滚动起来

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" >`enter code here` 

    <ViewFlipper 
     android:id="@+id/viewFlipper1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 
      <ImageView 
      android:layout_width="fill_parent" 
      android:layout_height="150dp" 
      android:src="@drawable/one" /> 
     <ImageView 
      android:layout_width="fill_parent" 
      android:layout_height="150dp" 
      android:src="@drawable/two" /> 

     <ImageView 
      android:layout_width="fill_parent" 
      android:layout_height="150dp" 
      android:src="@drawable/three" /> 

     <ImageView 
      android:layout_width="fill_parent" 
      android:layout_height="150dp" 
      android:src="@drawable/banner1" /> 

     <ImageView 
      android:layout_width="fill_parent" 
      android:layout_height="150dp" 
      android:src="@drawable/banner2" /> 

     <ImageView 
      android:layout_width="fill_parent" 
      android:layout_height="150dp" 
      android:src="@drawable/banner3" /> 

     <ImageView 
      android:layout_width="fill_parent" 
      android:layout_height="150dp" 
      android:src="@drawable/banner4" /> 
    </ViewFlipper>  

     <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Shop For" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:layout_marginLeft="100dp" /> 

     <GridView 
      android:id="@+id/gridView1" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:columnWidth="150dp" 
      android:gravity="center" 
      android:horizontalSpacing="1dp" 
      android:numColumns="2" 
      android:padding="28dp" 
      android:stretchMode="none" 
      android:verticalSpacing="1dp" 
      android:visibility="visible" > 
    </GridView> 


</LinearLayout> 

回答

2

将您的所有代码在滚动视图使用下面的代码

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

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

      <ViewFlipper 
       android:id="@+id/viewFlipper1" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" > 

       <ImageView 
        android:layout_width="fill_parent" 
        android:layout_height="150dp" 
        android:src="@drawable/one" /> 
       <ImageView 
        android:layout_width="fill_parent" 
        android:layout_height="150dp" 
        android:src="@drawable/two" /> 

       <ImageView 
        android:layout_width="fill_parent" 
        android:layout_height="150dp" 
        android:src="@drawable/three" /> 

       <ImageView 
        android:layout_width="fill_parent" 
        android:layout_height="150dp" 
        android:src="@drawable/banner1" /> 

       <ImageView 
        android:layout_width="fill_parent" 
        android:layout_height="150dp" 
        android:src="@drawable/banner2" /> 

       <ImageView 
        android:layout_width="fill_parent" 
        android:layout_height="150dp" 
        android:src="@drawable/banner3" /> 

       <ImageView 
        android:layout_width="fill_parent" 
        android:layout_height="150dp" 
        android:src="@drawable/banner4" /> 

      </ViewFlipper> 

      <TextView 
       android:id="@+id/textView1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Shop For" 
       android:textAppearance="?android:attr/textAppearanceMedium" 
       android:layout_marginLeft="100dp" /> 

      <GridView 
       android:id="@+id/gridView1" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:columnWidth="150dp" 
       android:gravity="center" 
       android:horizontalSpacing="1dp" 
       android:numColumns="2" 
       android:padding="28dp" 
       android:stretchMode="none" 
       android:verticalSpacing="1dp" 
       android:visibility="visible" /> 

     </LinearLayout> 

    </ScrollView> 

如果您有任何问题,请随时发表评论。

1

修改您的布局xml文件,就像下面这样,它会解决您的问题,我猜。

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

     <ViewFlipper 
      android:id="@+id/viewFlipper1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" > 
      <ImageView 
       android:layout_width="fill_parent" 
       android:layout_height="150dp" 
       android:src="@drawable/one" /> 
      <ImageView 
       android:layout_width="fill_parent" 
       android:layout_height="150dp" 
       android:src="@drawable/two" /> 

      <ImageView 
       android:layout_width="fill_parent" 
       android:layout_height="150dp" 
       android:src="@drawable/three" /> 

      <ImageView 
       android:layout_width="fill_parent" 
       android:layout_height="150dp" 
       android:src="@drawable/banner1" /> 

      <ImageView 
       android:layout_width="fill_parent" 
       android:layout_height="150dp" 
       android:src="@drawable/banner2" /> 

      <ImageView 
       android:layout_width="fill_parent" 
       android:layout_height="150dp" 
       android:src="@drawable/banner3" /> 

      <ImageView 
       android:layout_width="fill_parent" 
       android:layout_height="150dp" 
       android:src="@drawable/banner4" /> 
     </ViewFlipper> 

     <TextView 
      android:id="@+id/textView1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Shop For" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:layout_marginLeft="100dp" /> 

     <GridView 
      android:id="@+id/gridView1" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:columnWidth="150dp" 
      android:gravity="center" 
      android:horizontalSpacing="1dp" 
      android:numColumns="2" 
      android:padding="28dp" 
      android:stretchMode="none" 
      android:verticalSpacing="1dp" 
      android:visibility="visible" > 
     </GridView> 
    </LinearLayout> 
</ScrollView> 

这可能发生,因为您不使用ScrollViewScrollView应该只包含一个子视图。因此,使用LinearLayout作为所有其他视图的父视图,并使用此LinearLayout作为子视图到ScrollView

另外Gridview本身就是Scrollview,因此在您的情况下,GridView滚动,但其他视图不滚动。

+0

谢谢你的答案。我使用相同的代码,但它不工作滚动整个页面内容...还有什么可以做.. ..?请帮帮我 – vahni

相关问题