代码之家  ›  专栏  ›  技术社区  ›  Jim

堆积布局帮助

  •  0
  • Jim  · 技术社区  · 15 年前

    我正在尝试使用固定的页眉、可展开的正文和固定的页脚进行堆叠布局。我非常接近,但是带有WebView的正文部分显示在页脚后面,而不是页眉和页脚之间。蒂亚

    吉姆

    <?xml version="1.0" encoding="utf-8"?>
    
     <LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
       android:id="@+id/header"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
    
      <LinearLayout
       android:id="@+id/header"
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
    
        <ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:src="@drawable/icon" />
    
    
      <TextView  
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:text="Karen" />
    
     </LinearLayout>
    
     <RelativeLayout
       android:layout_width="wrap_content" 
          android:layout_height="fill_parent"
          android:layout_below="@id/header"
          >
    
    
     <WebView 
         android:id="@+id/webview"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:background="#000000"
      />
    
     <LinearLayout
     android:id="@+id/footer"
     android:layout_width='fill_parent'
     android:layout_height="wrap_content"
     android:layout_alignParentBottom="true"
     android:orientation="horizontal"
     android:background="#000000"
    >
    
    <EditText 
     android:id="@+id/inputText"
     android:layout_width="wrap_content"
     android:layout_height="fill_parent"
        android:text="Is on the bottom"
        android:layout_weight="1"
        android:textSize="15sp"
        /> 
    
     <Button
      android:layout_width="wrap_content"
     android:layout_height="fill_parent"
      android:textSize="15sp"
     android:text="send" />
    
     </LinearLayout>
    
    
     </RelativeLayout>
    
    </LinearLayout>
    
    2 回复  |  直到 15 年前
        1
  •  1
  •   CommonsWare    15 年前

    我正在尝试使用固定的页眉、可展开的正文和固定的页脚进行堆叠布局。

    步骤1:将根布局设为 RelativeLayout .

    步骤2:将标题添加为 相对布局 ,锚定在顶部( android:layout_alignParentTop="true" )

    步骤3:将页脚添加为 相对布局 ,锚定在底部( android:layout_alignParentBottom="true" )

    步骤4:将正文添加为 相对布局 ,锚定在收割台上( android:layout_below="..." 和页脚(A) ndroid:layout_above="..." )

        2
  •  0
  •   Jim    15 年前

    解决了的。

    我需要重新排序.xml文件中的项目,将中心项目(webview)放在底部,并添加android:layout_above=“@id/footer”。

    我了解到,当android处理id时,必须在使用之前定义它们,然后在android:layout_above=“@id/footer”等指令中进行定义。

    这很像页面加载时的javascript处理,必须在执行之前定义函数。

    顺便说一句,感谢StackOverflow的所有人,您使它成为开发人员的宝贵资源。