Android API 22中的固定页脚(Android 5.1(Lollipop))

时间:2015-08-30 13:01:38

标签: android android-layout android-activity

我是Android新手并尝试使用Android API 22开发应用。我无法获得固定的页脚。如何在活动中间使用可滚动内容固定页脚?要设置的属性是什么以及如何设置?

我有解决方案 - 设置'android:layout_alignParentBottom =“true”'可能适用于以前的API级别但现在已经过时。

3 个答案:

答案 0 :(得分:0)

试试(optional),它适用于我的应用。

答案 1 :(得分:0)

我通常这样做......

<强> layout.xml

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:paddingLeft="16dp"
            android:paddingRight="16dp">
            <LinearLayout
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <!-- The content: this is scrollable -->

            </LinearLayout>
        </ScrollView>

    <LinearLayout
        android:id="@+id/footer"
        style="@style/Footer"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentEnd="true">

        <!-- Stuff to go in your footer -->

    </LinearLayout>
</RelativeLayout>

<强> styles.xml

<style name="Footer" parent="Widget.AppCompat.ButtonBar" >
    <item name="android:background">@android:color/white</item>
    <item name="android:gravity">center_vertical|end</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:layout_width">match_parent</item>
    <item name="android:padding">4dp</item>
</style>

<强> V21 /样式

<style name="AppTheme.LinearLayout.Footer" parent="Widget.AppCompat.ButtonBar" >
    <item name="android:background">@android:color/white</item>
    <item name="android:gravity">center_vertical|end</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:layout_width">match_parent</item>
    <item name="android:padding">4dp</item>
    <item name="android:elevation">4dp</item>
</style>

这会创建一个漂亮的页脚,在Lollipop +设备上提升。

答案 2 :(得分:0)

你想做一些非常类似的事情:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

  <ScrollView
      android:layout_above="@+id/footer"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      >

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

    </LinearLayout>

  </ScrollView>

  <LinearLayout
      android:id="@+id/footer"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="horizontal"
      >

  </LinearLayout>

</RelativeLayout>
相关问题