2013-03-08 65 views
1

我想让我的布局通过添加ScrollView作为我的相对Layout.But我的布局滚动。我已经将fillport属性添加到true。ScrollView不适用于相对布局

这里是我的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> 

在这里,我已经使用了滚动,但布局的全部内容并不像showing.As卷轴不在这里工作。

+0

嘿Selvin都FILL_PARENT和match_parent是同样的事情。请建议我解决它。 – 2013-03-08 12:36:51

回答

-1

尝试删除这条线,并检查

android:fillViewport="true" 

,你也可以尝试的RelativeLayout的高度match_parent的WRAP_CONTENT代替

<RelativeLayout 

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

    > 
+1

'match_parent'的高度在垂直'ScrollView'中没有意义。 – Shade 2013-03-08 12:42:02

+0

嘿Nirali我尝试过,但我尝试这个后,我的布局变得很奇怪。请给我一个解决方案。 – 2013-03-08 12:44:28

+0

我已经将layout_height设置为wrap_content for ScrollView,但它不适用于我 – 2013-03-08 12:46:07