【问题标题】:Multiple LinearLayout in ScrollViewScrollView 中的多个 LinearLayout
【发布时间】:2015-04-04 04:13:59
【问题描述】:

我被困在试图在 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" />

问题!! 我只能看到前 2 个片段。

但是当我在我的主布局(来自 Activity 的那个)中硬编码 LinearLayout 的 layout_height 时,它工作得很好!但我不想硬编码它,因为我不知道它会占用多少空间,它应该是动态的 wrap_content。

有什么想法吗??为什么会这样?

谢谢!

【问题讨论】:

    标签: java android android-layout scrollview android-linearlayout


    【解决方案1】:

    试试这个代码...

    在 Scrollview 中设置以下属性

    android:fillViewport="true"
    

    【讨论】:

      【解决方案2】:

      试试这个修改后的布局:

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

      希望对您有所帮助!

      【讨论】:

      • 刚刚修改了答案,你可以再试一次。请复制整个布局
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多