【发布时间】:2012-08-24 01:46:55
【问题描述】:
我有一个 ScrollView,其中包含一个子项(由 LinearLayout 包装的元素)。有时这个孩子的高度是视口高度的一半,有时更大。
这里的布局:
<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>
当屏幕尺寸和密度较低时,子项可以正确显示在 ScrollView 中,但是当在 HDPI 和 XHDPI 等更大的屏幕上渲染此 Activity 时,内容会放在 ScrollView 的顶部。
有没有办法为 ScrollView 的唯一孩子设置重力,或者如果设备屏幕大于孩子的测量高度,我是否必须删除 scrollView?
【问题讨论】:
-
尝试将
android:layout_gravity="center"添加到滚动视图,其layout_width和layout_height为wrap_content -
非常感谢,成功了!您能否将此作为答案发布,以便我接受?
标签: android android-layout scrollview layout-gravity