简体   繁体   English

在其中包含包含视图的情况下实现Android滚动视图

[英]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 :| 嗨,我以前使用过ScrollView,但是由于某种原因,它现在还无法正常工作,现在最大的问题是我在此scrollView aint中添加的linear_view与它的父级匹配:| 屏幕截图


<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: 我到底在哪部分做错了,如果我将include视图放在没有scrollView和RelativeLayout的linearlayout内,那么一切就很好了,这是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 这就是我想要得到的最终结果:D 在此处输入图片说明

Try with the property isFillViewport so the scrollview can stretch 尝试使用isFillViewport属性,以便滚动视图可以拉伸

http://developer.android.com/reference/android/widget/ScrollView.html#isFillViewport() 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). 首先,应将ScrollView的子高度设置为wrap_content (用于垂直滚动)。 You're maybe looking for method fillViewport() . 您可能正在寻找fillViewport()方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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