SwipeRefreshLayout + another view

孤人 提交于 2019-12-23 18:43:55

问题


I have my layout setup as follows:

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

    <include layout="@layout/my_toolbar" />

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipe_refresh"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <com.my.SubView
            android:id="@+id/my_list_subview"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/white" />
    </android.support.v4.widget.SwipeRefreshLayout>

    <TextView
        android:id="@+id/text_content"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="@dimen/padding_medium"
        android:layout_margin="@dimen/padding_medium"
        android:text="Hello"
        android:textSize="14sp"
        android:maxLines="3"/>

</LinearLayout>

The problem is that the SwipeRefreshLayout takes up the entire screen and the textview doesn't show up at all.

The blue line in the above image is where the text view is. Is there anything I am missing? This seems to be so simple a problem, its ludicrous!

Image 2 in response to the answer by @Tomar


回答1:


try this

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

    <include layout="@layout/my_toolbar"
        android:id="@+id/top_layout"/>

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipe_refresh"
        android:layout_width="match_parent"
        android:layout_above="@+id/text_content"
        android:layout_below="@+id/top_layout"
        android:layout_height="wrap_content">
        <com.my.SubView
            android:id="@+id/my_list_subview"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/white" />
    </android.support.v4.widget.SwipeRefreshLayout>

    <TextView
        android:id="@+id/text_content"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="@dimen/padding_medium"
        android:layout_margin="@dimen/padding_medium"
        android:text="Hello"
        android:textSize="14sp"
        android:layout_alignParentBottom="true"
        android:maxLines="3"/>

</RelativeLayout>



回答2:


As I mentioned above, I worked it out with ConstraintLayout as below. I do not know why I need to use a large bottom margin and padding in the swipe refresh layout for it to sit above the text. Without these, it doesn't work!

<android.support.constraint.ConstraintLayout 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:background="@color/white"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <include layout="@layout/toolbar"
        android:id="@+id/my_toolbar"
        android:layout_height="wrap_content"
        android:layout_width="0dp"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"/>

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipe_refresh"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/padding_large"
        android:paddingBottom="@dimen/padding_super_large"
        app:layout_constraintTop_toBottomOf="@+id/my_toolbar"
        app:layout_constraintBottom_toTopOf="@+id/text_content"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent">
        <com.my.SubView
            android:id="@+id/my_list_subview"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:background="@color/white"/>
    </android.support.v4.widget.SwipeRefreshLayout>

    <EditText
        android:id="@+id/text_content"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:background="@color/white"
        android:hint="@string/write_message"
        android:textSize="14sp"
        android:maxLines="3"
        android:padding="@dimen/padding_medium"
        android:paddingLeft="@dimen/padding_large"
        app:layout_constraintTop_toBottomOf="@+id/swipe_refresh"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        tools:visibility="visible"
        tools:layout_editor_absoluteX="0dp" />

</android.support.constraint.ConstraintLayout>


来源:https://stackoverflow.com/questions/44787257/swiperefreshlayout-another-view

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