ScrollView not Working - Relative Layout

余生长醉 提交于 2020-01-05 07:31:12

问题


I am trying to wrap a realtive view in a scrollview as per the code below. However the problem is that the view doesn't scroll, even though part of the view is off the screen. I am testing this on the emulator.

<?xml version="1.0" encoding="UTF-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scroller"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
 >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background"
android:orientation="vertical"
> 
<TextView 
android:id="@+id/namedetail"
android:background="@drawable/backgroundstate"
android:layout_width="fill_parent"
android:gravity="center_vertical|center_horizontal" 
android:layout_height="50dip"
android:textColor="#FF000000"
android:textStyle="bold"
android:textSize="15sp"
android:typeface="sans" 
  />      
<ImageView android:id="@+id/picturedetail"
android:layout_width="175dip"
android:layout_height="175dip"
android:layout_below="@id/namedetail"
android:layout_marginLeft="75dip"
android:layout_marginTop="10dip"
/>
<ImageView android:id="@+id/infoboxdetail"
android:layout_width="225dip"
android:layout_height="100dip"
android:layout_marginLeft="50dip"
android:layout_marginTop="10dip"
android:layout_below="@id/picturedetail"
android:background="@drawable/backgroundstate"
/>
<TextView 
android:id="@+id/descriptiondetail"
android:background="@drawable/backgroundstate"
android:layout_width="fill_parent"
android:gravity="center_vertical|center_horizontal" 
android:layout_height="50dip"
android:textColor="#FF000000"
android:textStyle="bold"
android:textSize="15sp"
android:typeface="sans" 
android:layout_below="@id/infoboxdetail"
android:layout_marginTop ="10dip"
/>  
</RelativeLayout>
</ScrollView>

EDIT

OK solved - user stupidity - the bottom text box was off the screen on my monitor but not in the emulator. Making it longer makes it now scroll.


回答1:


Your RelativeLayout is horizontal and you use a ScrollView, try a HorizontalScrollView instead.




回答2:


I believe this is because the RelativeLayout doesn't stretch based on content. The ScrollView will fill the screen and then the RelativeLayout will fill the ScrollView. The size of the RelativeLayout will not change as you put widgets into it.

I would try using another type of layout - perhaps a TableLayout og a combination of nested LinearLayout.

Is there any specific reason why you're using the RelativeLayout?



来源:https://stackoverflow.com/questions/7349022/scrollview-not-working-relative-layout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!