将布局放在另一个上面

时间:2018-01-01 07:25:27

标签: android android-layout layout

我已经搜索了很多,但找不到任何工作方法来实现这一点,我有一个简单的片段布局。这是

$ adb shell am start -n '<package-name>/<activitiy>'

在此布局中,我有一个<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,我不想这样做。我知道在Frame布局中,视图的顺序表示z索引,但为什么当我使minbuildsdk布局不可见时,它不会显示error__。如果我手动更改xml中的视图顺序,这将适用于recyleview,但问题出现在recycleview布局上。我的意思是当我隐藏顶视图时,它没有显示其底部视图。

3 个答案:

答案 0 :(得分:1)

以下代码是正确的,你应该把你的include外部刷新布局:

def l2_angle_distance(pred, tgt):
    with tf.name_scope("L2AngleDistance"):
        # Scaling factor
        count = tgt[...,0,0]
        scale = tf.to_float(tf.count_nonzero(tf.is_finite(count)))
        # Mask NaN in tgt
        tgt = tf.where(tf.is_nan(tgt), pred, tgt)
        # Calculate L1 losses
        losses = tf.losses.cosine_distance(pred, tgt, -1, reduction=tf.losses.Reduction.NONE)
        # Square the losses, then sum, to get L2 scalar loss.
        # Divide the loss result by the scaling factor.
        return tf.reduce_sum(losses * losses) / scale

答案 1 :(得分:1)

更新以下方法:

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>

答案 2 :(得分:1)

也可以使用这样的布局

<?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>

并使用View.Gone代替View.Invisible

 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);
    }
}