程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> android-在scrollview 中平均分配3個視圖

android-在scrollview 中平均分配3個視圖

編輯:編程綜合問答
在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>

最佳回答:


你的 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. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved