Len*_*art 6 android android-scrollview
My main Activity has a number of buttons, that fit below each other on a large Tablet screen, but not on a smaller Phone screen. I added a ScrollView, so that the user can scroll down to the other buttons if the screen size requires it:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/bg"
android:gravity="center_horizontal">
<TextView
android:id="@+id/trackSelectorText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="foo" />
<!-- More buttons -->
</LinearLayout>
</ScrollView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
This kinda works, however I have a large blank space below the last button (i.e. the ScrollView can scroll down too far). Both on an actual Tablet and on the emulator with a Phone configuration. If I center the inner LinearLayout (instead of center_horizontal), the space is evenly spread between the top and the bottom, which I don't want neither. How do I fix this layout?
I hope this image makes it more clear, imagine that the ScrollView has been completely scrolled down and showing the last buttons. The blank space I mean is the one below Button 6 on the right image:

Len*_*art 11
实际上,它与布局没有关系(除非我遗漏了什么).我试着评论背景归属,它突然起作用了.背景imaged(@drawable/bg)太大了,导致滚动.我将背景转换为9个补丁图像,因此它可以自动缩放,而且,额外的空间消失了.尽管如此,如果没有9补丁可以实现这一点,我仍然有兴趣听听是否可以在XML文件中完成.
小智 9
尝试将此属性添加到ScrollView元素.机器人:fillViewport = "真"
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:fillViewport="true" > ... </ScrollVIew>
Run Code Online (Sandbox Code Playgroud)
参考:ScrollView参考
| 归档时间: |
|
| 查看次数: |
12904 次 |
| 最近记录: |