将一个块在滚动型的中心 [英] Place a block at the center of a ScrollView
问题描述
我有一个滚动型
包含一个孩子(元素包裹一个LinearLayout中)。有时这个孩子的身高一半的视口的高度,有时是更大的。
I have a ScrollView
that contains a single child (elements wrapped by a LinearLayout). Sometime this child's height is half of the viewport's height, sometime it is bigger.
下面的布局:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:background="@color/some_background">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="@drawable/fond_consult"
android:orientation="vertical"
android:weightSum="2">
... Some TextViews and ImageViews...
</LinearLayout>
</ScrollView>
当所述屏幕大小和密度低,孩子正确地显示在滚动型,但呈现像HDPI和XHDPI一个更大的屏幕上该活动时,该内容被放置在滚动型的顶部。
When the screen size and density is low, the child is correctly displayed in the ScrollView, but when rendering this activity on a bigger screen like HDPI and XHDPI, the content is placed at the top of the ScrollView.
有什么办法来设置重力为滚动型的唯一的孩子,还是我都删除了滚动视图,如果该设备的屏幕大于孩子的measered高度?
Is there any way to set gravity for the sole child of the ScrollView, or do I have to delete the scrollView if the device screen is bigger than the measered height of the child ?
推荐答案
你可以做的是尝试添加安卓layout_gravity =中心
到滚动型
及其 layout_width
和 layout_height
为 WRAP_CONTENT
。作为滚动型管理本身到其子布局的高度和宽度。
What you can do is try adding android:layout_gravity="center"
to ScrollView
with its layout_width
and layout_height
as wrap_content
. As ScrollView manages itself to the height and width of its child layouts.
这篇关于将一个块在滚动型的中心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!