1

我正在尝试通过将 ScrollView 添加为我的相对布局的父级来使我的布局可滚动。但我的布局没有滚动。我已将 fillport 属性添加为 true。

这是我的xml文件:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/scrollView2"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fillViewport="true"

            >

    <RelativeLayout 

        android:layout_width="match_parent"
        android:layout_height="wrap_content"

        >

        <TextView
            android:id="@+id/repActivityTitle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:ellipsize="middle"
            android:textSize="18sp"
            android:background="@android:color/darker_gray"
            android:text="@string/representativeTitle" />

        <TextView
            android:id="@+id/repStreet"
            android:layout_width="100dip"
            android:layout_height="wrap_content"
            android:layout_alignTop="@+id/repImage"
            android:layout_marginTop="14sp"
            android:layout_toRightOf="@+id/repImage"
            android:layout_margin="3sp"
            android:text="@string/repStreet" />

        <TextView
            android:id="@+id/repState"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/repStreet"
            android:layout_toRightOf="@+id/repImage"
            android:text="@string/repState" />

        <TextView
            android:id="@+id/repCountry"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/repState"
            android:layout_below="@+id/repState"
            android:text="@string/repCountry" />

        <com.google.android.maps.MapView
            android:id="@+id/repMap"
            android:layout_width="100dip"
            android:layout_height="100dip"
            android:paddingTop="2dp"
             android:layout_marginTop="2dp"
            android:layout_alignParentRight="true"
            android:layout_alignTop="@+id/repImage"
            android:apiKey="0lsQmtr2D241pSL53j0vQ2lYUs4_ZIWkIHyHAKw" >
        </com.google.android.maps.MapView>

        <View
            android:id="@+id/firstHorizontalLine"
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/repMap"
            android:layout_marginTop="54dp"
            android:background="@android:color/black" />

        <TextView
            android:id="@+id/issues2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/issues1"
            android:layout_centerVertical="true"
            android:text="@string/issues2" />

        <View
            android:id="@+id/secondHorizontalLine"
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/accomplishments"
            android:background="@android:color/black" />

        <TextView
            android:id="@+id/issues"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:layout_alignBottom="@+id/firstHorizontalLine"
            android:layout_alignRight="@+id/repStreet"
            android:text="@string/issues" />

        <TextView
            android:id="@+id/accomplish2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/accomplish1"
            android:layout_below="@+id/accomplish1"
            android:layout_marginTop="18dp"
            android:text="@string/accomplishments2" />

        <TextView
            android:id="@+id/promises"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/issues"
            android:gravity="center"
            android:layout_below="@+id/accomplish2"
            android:text="@string/promises" />

        <View
            android:id="@+id/thirdHorizontalLine"
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="@android:color/black"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/promises" />

        <TextView
            android:id="@+id/accomplishments"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/issues2"
            android:gravity="center"
            android:layout_toLeftOf="@+id/repMap"
            android:text="@string/accomplishments" />

        <TextView
            android:id="@+id/accomplish1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/secondHorizontalLine"
            android:layout_marginTop="21dp"
            android:text="@string/accomplishments1" />

        <TextView
            android:id="@+id/issues1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@+id/issues2"
            android:layout_alignParentLeft="true"
            android:layout_marginBottom="14dp"
            android:text="@string/issues1" />




        <ImageView
            android:id="@+id/repImage"
            android:layout_width="100dip"
            android:layout_height="100dip"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/repActivityTitle"
            android:contentDescription="@string/representativeImage"
            android:paddingTop="2dp"
            android:layout_marginTop="2dp"
            android:scaleType="centerCrop"
            android:src="@drawable/icon" />

        <TextView
            android:id="@+id/promise1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/thirdHorizontalLine"
            android:layout_marginTop="19dp"
            android:text="@string/promises1" />

        <TextView
            android:id="@+id/promise2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/promise1"
            android:text="@string/promises2" />

    </RelativeLayout>

    </ScrollView>

在这里,我使用了 ScrollView,但布局的全部内容没有显示出来。因为滚动在这里不起作用。

4

1 回答 1

-1

尝试删除此行并检查

android:fillViewport="true"

你也可以尝试将 relativelayout 的高度改为 match_parent 而不是 wrap_content

    <RelativeLayout 

    android:layout_width="match_parent"
    android:layout_height="match_parent"

    >
于 2013-03-08T12:40:04.727 回答