Adjust SwipeRefreshLayout height to place View at the bottom of it

风流意气都作罢 提交于 2019-12-10 14:12:46

问题


I have SwipeRefreshLayout inside a RelativeLayout. The problem is that SwipeRefreshLayout takes all the place on the screen, and I need to put a view after this view.

See picture: I have: 1st view, I need: 2nd view at the very bottom of the screen but with some space at a top.

My sample XML is:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="ru.seniorsolutions.freelansim.Orders"
    tools:showIn="@layout/app_bar_orders"
    android:paddingTop="10dp"
    android:id="@+id/layout_base">

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/refreshContainer"
        android:layout_width="match_parent"
        android:layout_height="450dp"
        android:layout_marginBottom="30dp">
            <ListView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:id="@+id/lvOffers"
                android:choiceMode="singleChoice"
                android:fastScrollEnabled="false" />
    </android.support.v4.widget.SwipeRefreshLayout>

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal" android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="20dp"
        android:paddingRight="20dp"
        android:measureWithLargestChild="false"
        android:layout_alignParentBottom="false"
        android:layout_alignParentLeft="false"
        android:layout_alignParentStart="false"
        android:layout_alignParentEnd="true"
        android:layout_alignBottom="@+id/refreshContainer">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="prev"
            android:id="@+id/tvPrevPage"
            android:textColor="#5bb3ee"
            android:textStyle="bold" />

        <View
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_weight="1" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="next"
            android:id="@+id/tvNextPage"
            android:textColor="#5bb3ee"
            android:textStyle="bold" />
    </LinearLayout>

</RelativeLayout>

回答1:


give android:layout_alignParentBottom="true" to your LinearLayout

<LinearLayout 
    android:orientation="horizontal" 
    android:layout_width="fill_parent"
    android:layout_alignParentBottom="true
    android:id="@+id/ll"
    .....
</LinearLayout>

and set SwipeRefreshLayout above the LinearLayout, also give its height to match_parent

<android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/refreshContainer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@id/ll"
    android:layout_marginBottom="30dp">


来源:https://stackoverflow.com/questions/34303795/adjust-swiperefreshlayout-height-to-place-view-at-the-bottom-of-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!