[英]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.