[英]How to keep scroll bar position always at the top of the view?
I am making a layout in which I am using a Scrollview to put the stuff in the view. 我正在做一个布局,在其中使用Scrollview将内容放入视图中。 But when in the view, I moved the scrollbar down and then moved to next view, the scrollbar remained at the same position, meaning, at the bottom part of the view.
但是在视图中时,我将滚动条向下移动,然后移至下一个视图,该滚动条保持在相同位置,即在视图的底部。 I want to make sure that the scrollbar remains at the top of the view always, by default.
我想确保默认情况下滚动条始终保持在视图顶部。 This is the XML:
这是XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerHorizontal="true"
android:orientation="vertical" >
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="90.0dip"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_marginTop="1.0dip"
android:fadeScrollbars="true"
android:fadingEdge="none"
android:fillViewport="true" >
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="visible" >
<ImageView
android:id="@+id/explain_QuestionImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="visible" />
<TextView
android:id="@+id/explain_question"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@id/explain_QuestionImageView"
android:fadingEdge="vertical"
android:scrollbars="vertical"
android:text=""
android:textColor="@color/question_text"
android:textColorHighlight="@color/question_text1" />
<TextView
android:id="@+id/explain_separator"
android:layout_width="match_parent"
android:layout_height="5.0dip"
android:layout_alignParentRight="true"
android:layout_below="@id/explain_question"
android:background="@drawable/blue_gradient"
android:fadingEdge="vertical"
android:padding="10dp"
android:scrollbars="vertical"
android:text="" />
<TextView
android:id="@+id/explain_explaination"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@id/explain_separator"
android:fadingEdge="vertical"
android:padding="10dp"
android:scrollbars="vertical"
android:text=""
android:textColor="@color/dark_green" />
</LinearLayout>
</FrameLayout>
</ScrollView>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
>
<com.google.ads.AdView
android:id="@+id/ad"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:keepScreenOn="true"
ads:adSize="BANNER"
ads:adUnitId="a1501e5633125fb"
ads:loadAdOnCreate="true"
ads:testDevices="TEST_EMULATOR, 123456789ABCDEF" >
</com.google.ads.AdView>
<LinearLayout
android:id="@+id/LL_Buttons1"
android:layout_width="fill_parent"
android:layout_height="40.0dip"
android:layout_above="@id/ad"
android:layout_gravity="bottom"
android:background="#ff777777"
android:orientation="horizontal" >
<Button
android:id="@+id/PrevExplainationButton"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true"
android:layout_marginLeft="2.0dip"
android:layout_weight="1.0"
android:background="@drawable/ibtn"
android:onClick="onPrevExplainationButtonClick"
android:text="Previous" />
<Button
android:id="@+id/NextExplainationButton"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true"
android:layout_marginLeft="5.0dip"
android:layout_marginRight="2.0dp"
android:layout_weight="1.0"
android:background="@drawable/ibtn"
android:onClick="onNextExplainationButtonClick"
android:text="Next" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
Please tell me how to do that. 请告诉我该怎么做。
Please tell me how to do that.
请告诉我该怎么做。
Your question is ambiguous. 您的问题不明确。 If the
ScrollView
remains where you scroll after you go to the next/previous question simply use the the method scrollTo
on the ScrollView
like this when you switch questions: 如果转到下一个/上一个问题后
ScrollView
仍保留在您滚动的位置,则在切换问题时,只需像下面这样在ScrollView
上使用方法scrollTo
:
((ScrollView)findViewById(R.id.scrollView1)).scrollTo(0, 0);
If you go to a new activity and want the ScrollView
at the start position then simple place the above line in the onResume
method of the Activity
. 如果您转到一个新的活动并希望将
ScrollView
放在开始位置,则只需将以上行放在Activity
的onResume
方法中即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.