Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/215.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何强制版面内容退出屏幕_Android_Xml_Layout - Fatal编程技术网

Android 如何强制版面内容退出屏幕

Android 如何强制版面内容退出屏幕,android,xml,layout,Android,Xml,Layout,我要重新创建此布局: 我设法做到了,但布局也可以改变为: 这会迫使部分内容退出屏幕 为了使更改可见,我设置了一个隐藏布局,该布局与按下某个按钮并消失时显示的额外布局相对应 这是我做的: 额外内容可见时的结果: 以下是XML: <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.co

我要重新创建此布局:

我设法做到了,但布局也可以改变为:

这会迫使部分内容退出屏幕

为了使更改可见,我设置了一个隐藏布局,该布局与按下某个按钮并消失时显示的额外布局相对应

这是我做的:

额外内容可见时的结果:

以下是XML:

<?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="match_parent"
    android:layout_height="wrap_content">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:orientation="vertical"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="120dp"
            android:layout_marginBottom="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            android:orientation="horizontal"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.02">

            <LinearLayout
                android:id="@+id/edit_holder"
                android:layout_width="325dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:baselineAligned="false"
                android:orientation="horizontal"
                android:visibility="visible"
                android:weightSum="2">

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginEnd="10dp"
                    android:layout_marginTop="50dp"
                    android:layout_weight="1"
                    android:background="@drawable/del_border"
                    android:gravity="center"
                    android:orientation="horizontal">

                    <ImageView
                        android:id="@+id/del_item"
                        android:layout_width="20dp"
                        android:layout_height="20dp"
                        android:layout_weight="1"
                        app:srcCompat="@drawable/ic_clear_bege_20dp" />

                </LinearLayout>

                <LinearLayout
                    android:id="@+id/spinner_holder"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:orientation="horizontal">

                    <LinearLayout
                        android:id="@+id/spinner_border"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:background="@drawable/spinner"
                        android:orientation="horizontal">

                        <Spinner
                            android:id="@+id/spinner_edit"
                            android:layout_width="30dp"
                            android:layout_height="40dp"
                            android:layout_weight="1" />
                    </LinearLayout>
                </LinearLayout>

            </LinearLayout>

            <ImageView
                android:id="@+id/img"
                android:layout_width="239dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:foreground="@drawable/rounded_corners"
                android:scaleType="fitXY"
                app:srcCompat="@mipmap/ic_launcher"
                tools:ignore="ContentDescription" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/nome_prod"
                    android:layout_width="165dp"
                    android:layout_height="32dp"
                    android:layout_marginStart="5dp"
                    android:text="TextView"
                    android:textColor="@color/preto_escuro" />

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="25dp"
                    android:orientation="horizontal"
                    android:weightSum="3">

                    <TextView
                        android:id="@+id/tam_txt"
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_marginStart="5dp"
                        android:layout_weight="1"
                        android:text="@string/tamanho"
                        android:textColor="@color/por_usar" />

                    <TextView
                        android:id="@+id/tam_val"
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:text="TextView"
                        android:textStyle="bold" />

                    <TextView
                        android:id="@+id/preco_ant"
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_marginEnd="5dp"
                        android:layout_weight="1"
                        android:gravity="end"
                        android:text="TextView"
                        android:textColor="@color/fade" />
                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:orientation="horizontal"
                    android:weightSum="4">

                    <TextView
                        android:id="@+id/cor_t"
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_marginStart="5dp"
                        android:layout_weight="0.6"
                        android:text="@string/cor"
                        android:textStyle="bold" />

                    <TextView
                        android:id="@+id/cor"
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="1.2"
                        android:text="TextView" />

                    <TextView
                        android:id="@+id/quanti"
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:gravity="end"
                        android:text="X x" />

                    <TextView
                        android:id="@+id/preco_fin"
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_marginEnd="5dp"
                        android:layout_weight="1.2"
                        android:gravity="end"
                        android:text="TextView"
                        android:textColor="@color/bege" />
                </LinearLayout>

            </LinearLayout>

        </LinearLayout>

        <View
            android:id="@+id/line"
            android:layout_width="fill_parent"
            android:layout_height="1dp"
            android:background="@color/preto_escuro" />

    </LinearLayout>

</android.support.constraint.ConstraintLayout>

注意:请忽略图像的不同形状,这与问题无关

为了让它更清楚,我只想知道,当隐藏的布局可见时,我如何才能“推出屏幕”布局中的部分内容。我不想要任何刷卡效果


提前感谢。

您可以使用需要添加的刷卡库之一

dependencies {
    compile 'com.android.support:recyclerview-v7:21.0.0'
    compile 'com.android.support:support-v4:20.+'
    compile "com.daimajia.swipelayout:library:1.2.0@aar"
}
这将在XML的顶部显示

<com.daimajia.swipe.SwipeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="80dp"
    app:clickToClose="true"> 

有关更多信息,请查看此GitHub存储库


您可以使用对象动画师编写动画功能来设置动画,然后随时启动它! 大概是这样的:

private void hideLayout(){
  float startX = yourLayout.getX();
  float endX = 0 - yourLayout.getX();
  ObjectAnimator anim
         = ObjectAnimator.ofFlot(yourLayout,view.X.startX,endX);
  anim.setDuration(500);
  anim.start();
}

你的问题是什么?@mTak我更新了问题,让它更清晰。只需将其可见性设置为
gone
@mTak问题是关于在“可见”时处理布局方面的问题,大多数情况下,它将处于“gone”状态,但按下按钮时,它可以变为“可见”。好的,你从左到右有一个线性布局,一个ImageView和另一个Linearlayout在xml中都是可见的。解释当第一个线性布局变为可见时,应将内容的哪一部分推出。可能我在问题中不清楚,但我不想要滑动功能,布局将是静态的,当隐藏布局变为可见时,它只会将部分内容“推出”不可见,你能帮我吗?正如我之前所说的,我不想要动画,因为这是在一个循环视图中使用的,它已经提供了一个平滑的转换