Android中如何增加ScrollView的高度?

2024-04-20

嗨朋友们,

我在用GridView里面一个ScrollView用于显示图像。在 GridView 中,我有 16 个动态添加的图像,但是ScrollView不显示全部 16 张图像(参见屏幕截图)。

我想要ScrollView显示整体GridView,有人知道我该如何解决这个问题吗?

谢谢大家。

xml 文件:

<?xml version="1.0" encoding="utf-8"?>
<merge android:layout_width="wrap_content" android:layout_height="340dip" xmlns:android="http://schemas.android.com/apk/res/android">
 <LinearLayout  android:id="@+id/LinearLayout01"  
 android:layout_width="fill_parent" 
 android:layout_height="320dip" android:orientation="vertical" 
 android:background="@color/black">
 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/scrollview"
            android:layout_width="fill_parent"
            android:layout_height="500dip"
            android:background="#ffffff"
            android:paddingTop="10dip"
            android:paddingLeft="5dip"
            android:layout_weight="1">

 <GridView 
                    android:id="@+id/jr_lookbook_grid" android:layout_width="fill_parent"
                    android:layout_height="fill_parent" android:numColumns="4"
                    android:verticalSpacing="10dp" android:horizontalSpacing="10dp"
                    android:columnWidth="90dp" android:stretchMode="columnWidth"
                    android:adjustViewBounds="true"
                    android:background="@drawable/shape"     

                    android:gravity="center"  android:layout_weight="1"/> 
</ScrollView>

                  <Button  android:id="@+id/click"
                  android:background="@android:color/transparent"
                   android:text="Load More Pictures..."

                   android:textColor="@color/white"
                   android:layout_width="fill_parent" android:layout_height="wrap_content"
                   android:layout_centerVertical="true"  />

</LinearLayout>
  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LinearLayout02_img"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:layout_gravity="center"
    android:layout_alignParentBottom="true"
    android:background="@color/black"
                android:layout_alignParentLeft="true"> 

    <WebView 
        android:id="@+id/webview"

        android:layout_width="fill_parent"

        android:layout_height="fill_parent"         
        android:scrollbars="none"  

    />
    <ImageView android:id="@+id/ImageView01" 
    android:layout_gravity="center_horizontal"
    android:scaleType="centerInside"
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent"

    android:adjustViewBounds="true">
</ImageView>

    </LinearLayout>
   <LinearLayout android:id="@+id/LinearLayout02"     android:background="#AA000000" 
         android:layout_width="400px"
        android:layout_height="50dip"
        android:layout_gravity="bottom"      
          >
                            <Button
                android:id="@+id/back"

                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
               android:background="@drawable/back1"
                android:layout_alignParentRight="true"
                android:layout_marginLeft="10dip"

              />

                 <Button
                  android:background="@drawable/forward5"
                android:id="@+id/next"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:layout_alignParentRight="true"
                android:layout_marginLeft="215dip"

                 />
</LinearLayout>

</merge>

使用属性android:fillViewport="true"在 XML 布局或使用方法中setFillViewport(true)在Java代码中。

看一下 :滚动视图文档 http://developer.android.com/reference/android/widget/ScrollView.html#attr_android:fillViewport

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Android中如何增加ScrollView的高度? 的相关文章

随机推荐