简体   繁体   English

ScrollView在相对布局上不起作用

[英]ScrollView not works on Relative Layout

I am trying to make my layout Scrollable by adding ScrollView as an parent for my Relative Layout.But my layout not scrolled.I have added the fillport property to true. 我正在尝试通过将ScrollView添加为相对布局的父级来使布局可滚动,但是布局没有滚动。我已经将fillport属性添加为true。

Here is my xml file: 这是我的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>

Here I have used the ScrollView but the full content of layout is not as showing.As scrolls not work here. 在这里我使用了ScrollView,但是布局的全部内容都没有显示出来。

Try to remove this line and check 尝试删除此行并检查

android:fillViewport="true"

And also you can try height of relativelayout to match_parent instead of wrap_content 而且您也可以尝试将relativelayout的高度设置为match_parent而不是wrap_content

    <RelativeLayout 

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

    >

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

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