3

我做了一个简单的布局xml文件。我一直在一点一点地解决我的问题。我正在使用scrollview、linearlayout 和tableview。我有一个顶栏,它被锁定在顶部。它从不移动。在中间,我有一个滚动视图,我需要将最后一个线性布局作为页脚放在底部,如果用户向下滚动,我不希望它消失。我想把它锁在那里。

这是我的代码

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

   <TableLayout
   android:layout_width="match_parent"
   android:layout_height="match_parent">

         <TableRow
        android:background="@drawable/gradient"
        android:gravity="center">

            .......

         </TableRow>

   </TableLayout>

    <ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/sw_layout"
android:orientation="vertical">

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

    <TableLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:background="#EEEEEE" >

        <TableRow
        android:id="@+id/tableRowDate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

            ..........

            </TableRow>

        </TableLayout>

        /*****************************************/
        /* I want this to be footer at the bottom*/
        /*****************************************/
        <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <Button
            android:id="@+id/btn_date"
            android:layout_height="35dp"
            android:padding="5dp"
            android:drawableLeft="@drawable/calendar"
            android:text="Tarih" />

            <Button
            android:id="@+id/btn_converter"
            android:layout_height="35dp"
            android:padding="5dp"
            android:drawableLeft="@drawable/calendar"
            android:text="Hesap" />
          </LinearLayout>
        /*****************************************/
        /* I want this to be footer at the bottom*/
        /*****************************************/

       </LinearLayout>
     </ScrollView>  
 </LinearLayout>

如何实现将页脚锁定在底部?

4

6 回答 6

20

您应该使用RelativeLayoutand 在页脚布局中添加标签:android:layout_alignParentBottom="true";对于你的ScrollView,你应该把它放在页脚布局(android:layout_above="@+id/idOfYourFooterLayout")之上

试试这个 :

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

  <ScrollView android:layout_width="fill_parent"
       android:layout_height="fill_parent"
       android:id="@+id/sw_layout"
       android:layout_above="@+id/footer"
       android:orientation="vertical">
//your UI...
  </ScrollView>

   <LinearLayout
      android:id="@+id/footer"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentBottom="true"
      android:orientation="vertical" >

      <Button
          android:id="@+id/btn_date"
          android:layout_height="35dp"
          android:padding="5dp"
          android:drawableLeft="@drawable/calendar"
          android:text="Tarih" />

      <Button
          android:id="@+id/btn_converter"
          android:layout_height="35dp"
          android:padding="5dp"
          android:drawableLeft="@drawable/calendar"
          android:text="Hesap" />
   </LinearLayout>
</RelativeLayout>
于 2013-06-18T09:30:32.390 回答
2

您可以设置layout_height="0dp"页眉、页脚ScrollView和定义layout_weight. 只是玩弄这些值,直到找出最有效的值。生成的页眉和页脚高度将随屏幕尺寸动态变化。

值 1, 5, 1 表示第一个元素占用 parent 中可用高度的 1/7,第二个 5/7 和最后一个 1/7 LinearLayout

尝试

<!-- HEADER -->
<TableLayout
   android:layout_width="match_parent"
   android:layout_height="0dp"
   android:layout_weight="1" >

<!-- BODY -->
<ScrollView
   android:layout_width="match_parent"
   android:layout_height="0dp"
   android:id="@+id/sw_layout"
   android:orientation="vertical"
   android:layout_weight="5">

<!-- FOOTER -->
<LinearLayout
   android:layout_width="match_parent"
   android:layout_height="0dp"
   android:orientation="vertical"
   android:layout_weight="1" >
于 2013-06-18T09:24:27.870 回答
1

使用 parent Layout 作为 RelativeLayout 并将此属性添加android:layout_alignParentBottom="true"到页脚布局中,并将 LinearLayout(页脚布局)放在滚动视图之外。像这样

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

   <LinearLayout
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentBottom="true"  //// add this property
      android:orientation="vertical" >

      <Button
          android:id="@+id/btn_date"
          android:layout_height="35dp"
          android:padding="5dp"
          android:drawableLeft="@drawable/calendar"
          android:text="Tarih" />

      <Button
          android:id="@+id/btn_converter"
          android:layout_height="35dp"
          android:padding="5dp"
          android:drawableLeft="@drawable/calendar"
          android:text="Hesap" />
   </LinearLayout>
于 2013-06-18T09:26:13.613 回答
0

像这样使用一个xml->>

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal">


</LinearLayout>

并将其包括为

LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">

  ...

  <!-- Overridden attributes never work. Nor do attributes like
       the red background, which is specified here. -->
  <include
      android:id="@+id/buttons_override"
      android:background="#ff0000"
      android:layout_width="fill_parent"
      layout="@layout/buttons"/>

</LinearLayout>
于 2013-06-18T09:19:53.597 回答
0

使用相对布局作为父布局,然后添加三个子视图,如下所示

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" >
    <View android:id="@+id/top_view"
     android:alignParentTop="true">  // Your view that as to be in Top 
    </View> 

     <ScrollView android:layout_below ="@id/top_view" > //scroll view in middle below topview
     </ScrollView>

    <View android:alignParentBotton="true">  //Your expected view in bottom
    </View>

</RelativeLayout>
于 2013-06-18T09:51:50.560 回答
0

就我而言,我在 Oncreate 函数和布局顶部添加了这些代码行

像下面

在此处输入图像描述

代码在这里:

    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN)
于 2021-11-04T10:43:19.230 回答