繁体   English   中英

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

[英]Implementing Androids Scroll-view with include view in it

嗨,我以前使用过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>

我到底在哪部分做错了,如果我将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" />

这就是我想要得到的最终结果:D 在此处输入图片说明

尝试使用isFillViewport属性,以便滚动视图可以拉伸

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

首先,应将ScrollView的子高度设置为wrap_content (用于垂直滚动)。 您可能正在寻找fillViewport()方法。

暂无
暂无

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

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