简体   繁体   中英

Implementing Androids Scroll-view with include view in it

Hi i've used ScrollView before but for some reason it aint working at all right now the greatest problem right now is that the linear_view i've added inside this scrollView aint matching it's parent :| 屏幕截图


<RelativeLayout 
            android:layout_width="match_parent"
        android:layout_height="match_parent"
          xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
     tools:context=".MainActivity">
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center_horizontal"
        android:orientation="vertical"
        android:weightSum="10"
         xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
     tools:context=".MainActivity" >





        <include
            android:id="@+id/myPostBox1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="4"
            layout="@layout/mycoolpostbox" />

   </LinearLayout> 
 </ScrollView>
</RelativeLayout>

Which part am i doing wrong exactly?Things work just fine if i put the include view inside the linearlayout without the scrollView and the RelativeLayout Here's the code inside the include:

<?xml version="1.0" encoding="utf-8"?>
   <LinearLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:weightSum="10"
            android:layout_weight="6" >

            <Space
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_weight="1" />

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_weight="8"
                android:background="#848484"
                android:orientation="vertical"
                android:weightSum="10" >

                <!-- <ImageView
                    android:id="@+id/box1_image"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_weight="6"
                    android:scaleType="centerCrop"
                    android:src="@drawable/ic_launcher" /> -->

            <WebView
                android:id="@+id/postImage1"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="6.95" />
            <WebView 
                android:id="@+id/myBody1"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="3"
               />
              <!--     <WebView 
                    android:id="@+id/myInfo1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="0.9"/> -->

                <Space
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="0.05"/>
                <!--   <TextView
                    android:id="@+id/myInfo2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="0.5"
                    android:text="Small Text"
                    android:textAppearance="?android:attr/textAppearanceSmall" /> -->

            </LinearLayout>
            <Space
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_weight="1" />

Here's what i want to get in the end :D 在此处输入图片说明

Try with the property isFillViewport so the scrollview can stretch

http://developer.android.com/reference/android/widget/ScrollView.html#isFillViewport()

First of all, ScrollView 's child height should be set wrap_content (for vertical scroll). You're maybe looking for method fillViewport() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM