I need a ScrollView which displays content in it's center if the screen is Big Enough, else it should display scroll.
Here is the example code that i used for testing
<ScrollView
android:id="@+id/maincontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/admob"
android:layout_below="@id/app_bar">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="abc1\nabc2\nabc3\nabc4\nabc5\nabc6\nabc7\nabc8\nabc9\nabc10\nabc11\nabc12\nabc13\nabc14\nabc15\nabc16\nabc17\nabc18\nabc19\nabc20\nabc21"
android:textSize="35sp"
android:textStyle="bold"/>
</LinearLayout>
</ScrollView>
My app needs to display in scrollview from abc1 to abc21. But instead it displays from abc 5 to abc21 with extra bottom space. check the screen shots attacked below:
here is the picture showing textview starting from abc5 instead of abc1:
here is the picture showing extra space below text view:
The extra space measures correct to the missing parts in textview and also the problem only erases when scroll needs to happen (i.e if content fits in screen and when scroll is not needed-their was on problem, when content is more and scroll is needed then the problem comes).
Update 1 :- added some landscape images
Top
Extra Space
End
Update 2: Once I removed the layout_gravity="center" the problem is solved, But I need that attribute. Because my content is dynamic and when small content need to be displayed it should be displayed in the center instead of top(which happens when I remove that attribute) and when content is large it needs to display the scroll.