歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android 中 ScrollView滾動不到最底端的解決方法

Android 中 ScrollView滾動不到最底端的解決方法

日期:2017/3/1 9:51:41   编辑:Linux編程

在用ScrollView包裹TextView時發現。滾動條有時候滾動不到最底端,原因是在TextView中設置了Android:layout_marginTop="20dp",導致marginTop之後,scrollView初始顯示的位置向下移動了20dp,你如果想要讓他正常顯示,必須在代碼裡面設置一下scrollView的初始顯示位置就可以了。mScrollView.smoothScrollTo(0,0).

當然可以去掉TextView的marginTop,在它上面的組件設置layout_marginBottom也是OK的,這樣ScrollView中的內容就可以完全顯示了,代碼如下

<ImageView
android:id="@+id/contentImage"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="3dp"
android:layout_weight="3"
android:layout_marginBottom="10dp"
android:background="@android:color/transparent"
/>

<ScrollView
android:layout_width="fill_parent"
android:layout_height="0dp"
android:scrollbars="vertical"
android:fadeScrollbars="false"
android:layout_weight="7">
<TextView
android:id="@+id/newsContent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="@string/content"
android:textColor="@android:color/black"

/>
</ScrollView>

Copyright © Linux教程網 All Rights Reserved