ScrollView 使我的背景图像变大,为什么?
我正在尝试制作一个具有嵌套relativeLayout 视图的滚动视图。真实布局有背景图像。当 realativeLayout 是唯一布局时,背景图像的大小就是我想要的大小。
当我添加滚动视图时,它会使图像变大,我不确定为什么以及需要设置哪些属性来修复它。
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout android:id="@+id/mainLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/background2"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView android:id="@+id/txtApplicationTitle"
android:text="My Application"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_marginTop="5dp"
android:textSize="15dp"
android:layout_alignParentTop="true"
android:layout_alignLeft="@+id/txtAbout" />
<TextView android:id="@+id/txtPrivacyHeader"
android:layout_width="wrap_content"
android:text="@string/PrivacyHeader"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="21dp"
android:layout_marginTop="94dp" />
<TextView android:id="@+id/Privacy"
android:layout_width="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/Privacy"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/txtPrivacyHeader"
/>
</RelativeLayout>
</ScrollView>
// 这就是我得到的(你看不出来,但它是可滚动的)
(source: gyazo.com)
// 这就是我想要的 SrcollView看看(这与上面的代码完全相同,只是没有 ScrollView 包裹它)
看看顶部的所有内容突然长这么大。
I am trying to make a scroll view that has a nested relativeLayout view. The realative layout has a background image. When the realativeLayout is the only layout the background image is the size I want it to be.
When I add scroll view it makes the image bigger and I am not sure why and what properties I need to set to fix it.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout android:id="@+id/mainLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/background2"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView android:id="@+id/txtApplicationTitle"
android:text="My Application"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_marginTop="5dp"
android:textSize="15dp"
android:layout_alignParentTop="true"
android:layout_alignLeft="@+id/txtAbout" />
<TextView android:id="@+id/txtPrivacyHeader"
android:layout_width="wrap_content"
android:text="@string/PrivacyHeader"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="21dp"
android:layout_marginTop="94dp" />
<TextView android:id="@+id/Privacy"
android:layout_width="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/Privacy"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/txtPrivacyHeader"
/>
</RelativeLayout>
</ScrollView>
// this is what I get (you can't tell but it is scrollable)
(source: gyazo.com)
// this how I want the SrcollView to look(this is the exact same code as above just without the ScrollView wrapping it)
(source: gyazo.com)
See how the top part has all of sudden grown so much.
您的
ScrollView
的高度设置为wrap_content
,您的RelativeLayout
的高度设置为fill_parent
。这意味着您的 ScrollView 将扩展到整个视图。Your
ScrollView
has its height set towrap_content
and yourRelativeLayout
has its height set tofill_parent
. That means yourScrollView
is going to expand to the entire view.