clcurie_11 2013-01-09 05:56 采纳率: 6.7%
浏览 4384
已采纳

在scrollview 中平均分配3个视图

我在scrollview中设计了3个视图,我想把这几个视图分配在整个scoll布局中。使用下面的代码,但是没有实现。

scrollview:

<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>
  • 写回答

2条回答 默认 最新

  • hxn_217 2013-01-10 05:57
    关注

    你的 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>
    

    对于spacers,我建议只使用Views,不用 LinearLayouts。view是一个容量小点的类,不会占用更多的资源。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)