Android 将布局置于另一布局之上
我已经搜索了很多,但找不到任何工作方法来实现这一点,我有一个简单的片段布局。给你Android 将布局置于另一布局之上,android,android-layout,layout,Android,Android Layout,Layout,我已经搜索了很多,但找不到任何工作方法来实现这一点,我有一个简单的片段布局。给你 <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"
<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
时遇到错误时,我都会使error\uuu
布局可见。但它不起作用。我使用此函数使其可见和不可见
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
,我不想这样做。我知道在框架布局中,视图顺序指示z索引,但为什么当我使error\uuu
layout不可见时,它不会显示recyleview
。如果我手动更改xml中视图的顺序,这将在recycleview
上起作用,但问题发生在error\uuu
布局上。我的意思是,当我隐藏顶视图时,它不会显示其底视图 下面的代码是正确的,您应该将您的include out刷新布局:
<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>
下面的代码是正确的,您应该将您的include-out刷新布局:
<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>
更新以下方法:
private void finishUpdate(Boolean status){
mSwipeRefreshLayout.setRefreshing(false);
if(status){
error__.setVisibility(View.GONE);
recyclerView.setVisibility(View.VISIBLE);
}else{
error__.setVisibility(View.VISIBLE);
recyclerView.setVisibility(View.GONE);
}
}
还使用以下内容更新片段:
<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>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="fill_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:visibility="gone">
</android.support.v7.widget.RecyclerView>
</RelativeLayout>
</android.support.v4.widget.SwipeRefreshLayout>
</FrameLayout>
更新以下方法:
private void finishUpdate(Boolean status){
mSwipeRefreshLayout.setRefreshing(false);
if(status){
error__.setVisibility(View.GONE);
recyclerView.setVisibility(View.VISIBLE);
}else{
error__.setVisibility(View.VISIBLE);
recyclerView.setVisibility(View.GONE);
}
}
还使用以下内容更新片段:
<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>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="fill_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:visibility="gone">
</android.support.v7.widget.RecyclerView>
</RelativeLayout>
</android.support.v4.widget.SwipeRefreshLayout>
</FrameLayout>
也要像这样使用布局
<?xml version="1.0" encoding="utf-8"?>
<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="match_parent"
tools:context="ir.gfpishro.signal.FragMalls">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycle_mall_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true">
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/activity_main_swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="250dp"
android:visibility="gone">
<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"
android:layout_centerInParent="true">
<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"
style="@style/ButtonOrange"
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"
app:layout_constraintTop_toBottomOf="@+id/text_content" />
</android.support.constraint.ConstraintLayout>
</android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>
</RelativeLayout>
也要像这样使用你的布局
<?xml version="1.0" encoding="utf-8"?>
<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="match_parent"
tools:context="ir.gfpishro.signal.FragMalls">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycle_mall_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true">
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/activity_main_swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="250dp"
android:visibility="gone">
<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"
android:layout_centerInParent="true">
<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"
style="@style/ButtonOrange"
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"
app:layout_constraintTop_toBottomOf="@+id/text_content" />
</android.support.constraint.ConstraintLayout>
</android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>
</RelativeLayout>
相对布局错误的参考是什么?这是你的错误吗?你能把你的设计的图像放进去吗?你的问题让人困惑。。。您只想在加载数据时显示布局错误,否则它应该不可见,对吗?@向导是的,这是我的error@Umair是的,这正是我要找的相对布局错误的参考是什么?这是你的错误吗?你能把你的设计的图像放进去吗?你的问题让人困惑。。。您只想在加载数据时显示布局错误,否则它应该不可见,对吗?@向导是的,这是我的error@Umair是的,这正是我想要的,但问题是当recylceview中没有任何内容时,我无法刷新我想如果您将相对布局错误设置为包装内容
,你可以拉刷新。怎么做?你是什么意思谢谢它工作了但唯一的问题是错误布局,它位于左上角,不在中心。我编辑了我的答案,你只需要将你的layout\u gravity
设置为center
,但问题是当我在recylceview中没有任何东西时,我无法刷新我想如果你将你的相对布局\u error
设置为wrap\u content
,你可以拉刷新。怎么做?你是什么意思谢谢它工作了但唯一的问题是错误布局,它位于左上角,不在中心。我编辑了我的答案,你只需要将你的layout\u gravity
设置为center
,但现在我无法拖动刷新recycleview@MajidHojati现在哪个布局不可见?但现在我无法拉刷新recycleview@MajidHojati现在哪个布局不可见?