Android:尝试将RelativeLayout集中在根ScrollView中
我希望ScrollView填充整个屏幕和相关布局,或者在ScrollView中居中显示内容,或者填充ScrollView并居中显示内容。scrollView就在那里,以防应用程序在小屏幕上运行 我已经实现了将RelativeLayout作为根的效果,但是当我添加scrollView作为包装时,我无法使它居中,RelativeLayout只是添加到顶部。我试着改变RelativeLayout的布局和高度,但这也不起作用,只是给了我一个警告 有趣的是,它在Eclipse中的图形布局上看起来很好Android:尝试将RelativeLayout集中在根ScrollView中,android,Android,我希望ScrollView填充整个屏幕和相关布局,或者在ScrollView中居中显示内容,或者填充ScrollView并居中显示内容。scrollView就在那里,以防应用程序在小屏幕上运行 我已经实现了将RelativeLayout作为根的效果,但是当我添加scrollView作为包装时,我无法使它居中,RelativeLayout只是添加到顶部。我试着改变RelativeLayout的布局和高度,但这也不起作用,只是给了我一个警告 有趣的是,它在Eclipse中的图形布局上看起来很好 &l
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<RelativeLayout
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fillViewport="true"
android:gravity="center" >
....
....
尝试将滚动视图
和相对视图
的高度和宽度更改为填充父视图
。如果这不起作用,请发布整个xml文件。您可以始终将RelativeLayout
放在一个线性布局中,使其居中
您遇到的问题是,ScrollView
没有重力属性,因此您需要在ScrollView
中使用另一个接受重力的布局
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center"
android:gravity="center">
<RelativeLayout
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fillViewport="true"
android:gravity="center" >
</RelativeLayout>
</LinearLayout>
</ScrollView>
将另一个
rootview
,RelativeLayout
或LinearLayout,
放在现有RelativeLayout中,并将这些属性添加到新的RelativeLayout中
android:layout_height="wrap_content"
android:layout_centerVertical="true"
经过一番周折,这才最终奏效
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
tools:context=".MainActivity" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center" >
你能发布一张它的外观图片,甚至是你的目标吗?很难说清楚你到底看到了什么以及你在想什么。试着在现有的RelativeLayout中加入另一个“rootview”,或者是RelativeLayout
或者LinearLayout
,然后制作一个新的android:layout\u height=“wrap\u content”android:layout\u centerVertical=“true”。@svenoaks我很高兴解决了你的问题。我根据评论发布了答案。;-)恐怕不是这样的,我最初的评论还为时过早