【问题标题】:Expanding animation layout扩展动画布局
【发布时间】:2016-12-04 16:34:41
【问题描述】:

我开始使用 Android Studio,但我在没有活动的情况下遇到了一些问题。

我想表示一个布局,点击它后,我想增加它的大小。

我认为 MaterialDesign 有办法做到这一点,但我真的不知道该怎么做。

我会用几张图片更好地解释它:

  • 在点击之前

  • 点击后

图片是用photoshop制作的,不是编码的。

所以,我想做的是增加布局中间的大小,如图所示。

我想知道你们中是否有人知道怎么做。

谢谢。

【问题讨论】:

  • 了解设置可见性。您可以根据需要设置可见和转到视图。单击即可显示不可见视图

标签: java android android-layout android-studio layout


【解决方案1】:

这不是“基本上”,抱歉。

这个想法是将您的布局分成 3 部分 - 例如。顶部,中间,底部 - 和动画“中间”尺寸变化。也许,还需要更改中间部分的可见性。

实现起来可能相当困难,尤其是如果您希望在第二次点击时将其向后滚动。

我自己的尝试就是基于这个例子 - https://github.com/Udinic/SmallExamples/tree/master/ExpandAnimationExample

【讨论】:

  • 你是对的。我知道做到这一点并不容易。我会检查你的例子。谢谢!
【解决方案2】:

我终于找到了解决方案。 只需将以下行添加到您想要展开或折叠的layout(以及之前的任何layouts

                android:animateLayoutChanges="true"

利用layout 的可见性,您可以展开或折叠它。

简单的方法,确实有效。

[已编辑]

如果您必须编写一些不同的视图,则解决方案的要点。有些是隐藏的,有些是显示的。

需要的代码如下:

  • Java 显示和隐藏所有视图所需的方法

    公共类 Principal_Activity 扩展 AppCompatActivity 实现 NavigationView.OnNavigationItemSelectedListener {

     public void tratar_primer_ranking() {
        //Ranking extendido - cerrado
        RelativeLayout ranking_1_completo = (RelativeLayout) findViewById(R.id.ranking_1_completo);
        ranking_1_completo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                RelativeLayout ocultar_layout_1_1 = (RelativeLayout) findViewById(R.id.ocultar_layout_1_1);
                RelativeLayout ocultar_layout_2_1 = (RelativeLayout) findViewById(R.id.ocultar_layout_2_1);
                LinearLayout ocultar_layout_4_1 = (LinearLayout) findViewById(R.id.ocultar_layout_4_1);
                if (!extendido_1) {
                    ocultar_layout_1_1.setVisibility(View.GONE);
                    ocultar_layout_2_1.setVisibility(View.VISIBLE);
                    ocultar_layout_4_1.setVisibility(View.VISIBLE);
                    extendido_1 = true;
                } else {
                    ocultar_layout_1_1.setVisibility(View.VISIBLE);
                    ocultar_layout_2_1.setVisibility(View.GONE);
                    ocultar_layout_4_1.setVisibility(View.GONE);
                    extendido_1 = false;
                }
            }
        });
    }
    

    }

  • XML

            <RelativeLayout
                android:id="@+id/parte_1_ranking_1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:animateLayoutChanges="true">
    
                <ImageView
    
                    android:id="@+id/verificable_1"
                    android:layout_width="15dp"
                    android:layout_height="15dp"
                    android:layout_marginLeft="50dp"
                    android:layout_marginTop="7dp"
                    android:background="@drawable/botonrojo" />
    
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:animateLayoutChanges="true"
                    android:orientation="horizontal">
    
                    <ImageView
                        android:id="@+id/imagen_categoria_1"
                        android:layout_width="60dp"
                        android:layout_height="60dp"
                        android:layout_margin="10dp"
                        android:background="@drawable/categoria_3" />
    
                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:animateLayoutChanges="true"
                        android:orientation="vertical">
    
                        <TextView
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:maxLength="60"
                            android:text="¿Cuántos toques al balón puedes dar con la pierna izquierda?"
                            android:textSize="15sp" />
    
                        <RelativeLayout
                            android:id="@+id/ocultar_layout_1_1"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:animateLayoutChanges="true">
    
                            <LinearLayout
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:animateLayoutChanges="true"
                                android:orientation="horizontal">
    
                                <RelativeLayout
                                    android:layout_width="match_parent"
                                    android:layout_height="wrap_content"
                                    android:animateLayoutChanges="true">
    
                                    <ImageView
                                        android:layout_width="30dp"
                                        android:layout_height="30dp"
                                        android:layout_marginLeft="20dp"
                                        android:layout_marginTop="5dp"
                                        android:background="@drawable/ic_perfil" />
    
                                    <TextView
                                        android:id="@+id/participantes_1_1"
                                        android:layout_width="wrap_content"
                                        android:layout_height="wrap_content"
                                        android:layout_marginLeft="55dp"
                                        android:layout_marginTop="10dp"
                                        android:numeric="integer"
                                        android:text="17" />
    
                                    <ImageView
                                        android:layout_width="30dp"
                                        android:layout_height="30dp"
                                        android:layout_alignParentRight="true"
                                        android:layout_marginRight="50dp"
                                        android:layout_marginTop="5dp"
                                        android:background="@drawable/actualizacion" />
    
                                    <TextView
                                        android:layout_width="wrap_content"
                                        android:layout_height="wrap_content"
                                        android:layout_alignParentRight="true"
                                        android:layout_marginRight="20dp"
                                        android:layout_marginTop="10dp"
                                        android:text="1d" />
                                </RelativeLayout>
                            </LinearLayout>
                        </RelativeLayout>
                    </LinearLayout>
                </LinearLayout>
            </RelativeLayout> <!--parte_1_ranking_1-->
    

【讨论】:

  • 你能告诉我们你的最终代码吗? xml和Java,请
  • 我已经编辑了我的答案。这是我很久以前编码的东西,所以我不确定它是否是你正在寻找的东西。我想这会有所帮助。我不能发布漏洞代码,因为它是我为我的论文做的,所以它真的很长。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-10-12
  • 2018-06-13
  • 2011-09-27
  • 1970-01-01
  • 1970-01-01
  • 2011-03-30
  • 1970-01-01
相关资源
最近更新 更多