我已经搜索了很多,但找不到任何工作方法来实现这一点,我有一个简单的片段布局。这里是
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="ir.gfpishro.signal.FragMalls">
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/activity_main_swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/relative_layout_error"
android:layout_width="match_parent"
android:layout_height="fill_parent">
<include
layout="@layout/wifi_error_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycle_mall_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:visibility="gone">
</android.support.v7.widget.RecyclerView>
</android.support.v4.widget.SwipeRefreshLayout>
</FrameLayout>
在这个布局中,我有一个recycleview
和一个relativelayout
,其中包括另一个布局。它被命名wifi_error_layout
,我称之为error__
布局
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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">
<ImageView
android:id="@+id/image_icon"
android:layout_width="108dp"
android:layout_height="108dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_no_connection_24dp_white"
tools:background="#000000"
tools:ignore="ContentDescription" />
<TextView
android:id="@+id/text_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:gravity="center"
android:textColor="@color/colorAccent"
android:textSize="15sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/image_icon"
tools:text="@string/progressActivityEmptyTitlePlaceholder" />
<TextView
android:id="@+id/text_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="56dp"
android:layout_marginRight="56dp"
android:layout_marginTop="10dp"
android:gravity="center"
android:lineSpacingExtra="5.5dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/text_title"
tools:text="@string/progressActivityEmptyContentPlaceholder" />
<Button
android:id="@+id/button_retry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="16dp"
android:text="@string/progressActivityErrorButton"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
style="@style/ButtonOrange"
app:layout_constraintTop_toBottomOf="@+id/text_content" />
</android.support.constraint.ConstraintLayout>
我希望它们相互重叠,每次我在加载数据时遇到错误时,recycleview
我都会使error__
布局可见。但它不起作用。我用这个函数让它可见和不可见
private void finishUpdate(Boolean status){
mSwipeRefreshLayout.setRefreshing(false);
if(status){
error__.setVisibility(View.INVISIBLE);
recyclerView.setVisibility(View.VISIBLE);
}else{
error__.setVisibility(View.VISIBLE);
recyclerView.setVisibility(View.INVISIBLE);
}
}
但我无法让它发挥作用。我尝试使用setZ
但它需要更改minbuildsdk
,我不想这样做。我知道在 Frame 布局中,视图的顺序表示 z 索引,但是为什么当我使error__
布局不可见时它不显示recyleview
. 如果我手动更改 xml 中视图的顺序,这将起作用,recycleview
但问题发生在error__
布局上。我的意思是当我隐藏顶视图时,它不会显示它的底视图。
下面的代码是正确的,你应该把你的包含放在刷新布局之外:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/activity_main_swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycle_mall_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"/>
</android.support.v4.widget.SwipeRefreshLayout>
<RelativeLayout
android:id="@+id/relative_layout_error"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="visible">
<include
layout="@layout/wifi_error_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>
</FrameLayout>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句