【问题标题】:ScrollView Makes my background image bigger why?ScrollView 让我的背景图片变大为什么?
【发布时间】:2011-08-03 20:38:41
【问题描述】:

我正在尝试制作具有嵌套 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>

//这是我得到的(你看不出来,但它是可滚动的)


(来源:gyazo.com

// 这就是我希望 SrcollView 的外观(这与上面的代码完全相同,只是没有 ScrollView 包装它)


(来源:gyazo.com

看看顶部是如何突然增长这么多的。

【问题讨论】:

  • 它在哪些方面使您的图像更大......? (宽度、高度、拉伸以适应等)。您是否也尝试过将滚动视图 layout_width 设置为 wrap_content?
  • @ Adam Storm - 身高越来越高了。当我将滚动视图包裹在真实布局周围时,我说至少要大 10-15%。我试过 wrap_content 似乎什么也没做。
  • @ Adam Storm - 我测量了我想要的高度(这是没有包裹相对布局的滚动条布局)是 71pxs。当我将滚动视图放在它周围时,它会变为 87pxs
  • 我会尝试将您的 RelativeLayout 嵌入到 ScrollView 的线性布局中:又名 YOUR_CODE 它似乎在那里是否正在进行一些奇怪的重新格式化优化
  • @Adamn Storm - 我会试试线性的高度和宽度应该设置多少?

标签: android android-layout scrollview android-relativelayout


【解决方案1】:

您的ScrollView 的高度设置为wrap_content,您的RelativeLayout 的高度设置为fill_parent。这意味着您的 ScrollView 将扩展到整个视图。

【讨论】:

  • 不应该展开整个视图吗?你认为它们应该是什么,所以我可以试试看。背景图像应该占据整个视图。它的顶部不应该如此拉伸。
  • 我更改了代码以表示我正在处理相同问题但更明显的不同视图。我还添加了一些屏幕截图。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-02-03
  • 2021-06-07
  • 2020-02-25
  • 2019-06-24
相关资源
最近更新 更多