【问题标题】:Distribute 3 views inside a scrollview evenly在一个滚动视图中均匀分布 3 个视图
【发布时间】:2012-07-26 23:24:57
【问题描述】:

我在滚动视图中有 3 个视图,我想将它们分布在整个 scoll 布局中。我没有让它正常工作,希望有人能看到这个问题。

我想要的是在滚动视图中:

<scrollview>
  <linear or relative view?>
    (filler)
    moneywheels
    (filler)
    timewheels
    timeWheelsText
    (filler)
  </linear or relative view?>
</scrollview>

非常感谢您的帮助!

<ScrollView
    android:id="@+id/ScrollView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="1" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="center"
        android:orientation="vertical"
        android:weightSum="3" >

        <LinearLayout
            android:id="@+id/fil1"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1" />

        <LinearLayout
            android:id="@+id/moneyWheels"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0">

            <!-- content -->

        </LinearLayout>

        <LinearLayout
            android:id="@+id/fill2"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1" />

        <LinearLayout
            android:id="@+id/timeWheels"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0"
            android:background="@drawable/time"
            android:padding="@dimen/padding" >

            <!-- content -->

        </LinearLayout>

        <LinearLayout
            android:id="@+id/timeWheelsText"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_gravity="center"
            android:layout_weight="0"
            android:gravity="top|center" >

            <!-- content -->

        </LinearLayout>

        <LinearLayout
            android:id="@+id/fill3"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1" />
    </LinearLayout>
</ScrollView>

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="0"
    android:gravity="bottom|center_horizontal"
    android:orientation="vertical" >

    <com.google.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ads:adSize="BANNER"
        ads:adUnitId="xxxxxxxxxxx"
        ads:loadAdOnCreate="true"
        ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID" />
</LinearLayout>

【问题讨论】:

  • 对于你的布局,是两个不同的文件,还是同一个?
  • 布局在一个文件中,是我在这里发布的。

标签: android android-layout layout scrollview


【解决方案1】:

您的布局 XML 文件无效。在处理 XML 时,您应该只拥有一个顶级标签。假设您希望广告显示在滚动视图下方,您需要以下内容:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="0"
    android:gravity="bottom|center_horizontal"
    android:orientation="vertical" >

    <ScrollView ...>
        <!-- Other pieces under scrollview go here -->
    </ScrollView>

    <com.google.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ads:adSize="BANNER"
        ads:adUnitId="xxxxxxxxxxx"
        ads:loadAdOnCreate="true"
        ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID" />
</LinearLayout>

另外,对于您的间隔,我建议只使用 Views,而不是 LinearLayouts。视图将是一个重量较轻的类,并且不会使用那么多资源。使用 LinearLayouts 作为间距也可能会引起其他意外。

【讨论】:

  • 谢谢!将 LinearLayouts 更改为 Views 并更改顶级标签解决了我的问题。
猜你喜欢
  • 2012-10-16
  • 1970-01-01
  • 1970-01-01
  • 2016-05-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多