簡體   English   中英

ScrollView中的多個LinearLayout

[英]Multiple LinearLayout in ScrollView

我陷入嘗試在ScrollView中插入多個LinearLayout或FrameLayout(無論如何)的問題。

我的結構是:

  • 活動
  • ...片段A
  • ...片段B
  • ...片段C

activity_layout.xml:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <LinearLayout
        android:id="@+id/container_main"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/border"
        android:orientation="horizontal"/>

    <LinearLayout
        android:id="@+id/container_gallery"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/border"
        android:orientation="horizontal"/>

    <LinearLayout
        android:id="@+id/container_video"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/border"
        android:orientation="horizontal"/>

</LinearLayout>

例如,我的片段之一具有以下布局:

<android.support.v4.view.ViewPager     xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context="com.arbiec.conex.activities.MainActivity" />

問題!! 我只能看到前兩個片段。

但是,當我在我的主布局(“活動”中的一個)中對LinearLayout的layout_height進行硬編碼時,它就可以正常工作! 但是我不想對其進行硬編碼,因為我不知道它會占用多少空間,它應該與wrap_content動態結合。

有任何想法嗎?? 為什么會這樣呢?

謝謝!

嘗試修改后的布局:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:orientation="vertical">

   <LinearLayout
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical">

      <FrameLayout
         android:id="@+id/container_main"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:background="@drawable/border"
         />

     <FrameLayout
        android:id="@+id/container_gallery"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/border"
        />

     <FrameLayout
        android:id="@+id/container_video"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/border"
        />

   </LinearLayout>

</ScrollView>

希望有幫助!

試試這個代碼...

在Scrollview中設置以下屬性

android:fillViewport="true"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM