如何让布局从底部向上滑动?

零点

单击按钮从底部获取 LinearLayout。但是有一个问题。

  1. 布局完成后,VideoView 不能一键工作。在第二次点击时起作用。

  2. 如果我触摸顶部布局以外的任何地方,我想让布局消失。(当然,点击后的 VideoView 应该不会工作。)

  3. 如果我单击 EditText,我想将 EditText 和按钮放在软键盘上。(它现在被软键盘遮挡了。)

这是我的代码。

代码

public class PlayActivity extends AppCompatActivity {

public void onCreate(){

  ...

videoView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(videoView.isPlaying()){      
                    videoView.pause();
                    playimg.setVisibility(View.VISIBLE);
                }else{                          
                    videoView.start();
                    playimg.setVisibility(View.INVISIBLE);
                }
            }
        });

...

comm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                if(!CommShown()){

                    Animation bottomUp = AnimationUtils.loadAnimation(PlayActivity.this,R.anim.bottom_up);
                    comm_layout.startAnimation(bottomUp);
                    comm_layout.setVisibility(View.VISIBLE);
                    viewGroup.setEnabled(false);
                    //enableDisableViewGroup(viewGroup, false);
                }


            }
        });


        comm_close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(CommShown()){
                        Animation bottomUp = AnimationUtils.loadAnimation(PlayActivity.this,R.anim.bottom_down);
                        comm_layout.startAnimation(bottomUp);
                        comm_layout.setVisibility(View.INVISIBLE);
                    enableDisableViewGroup(viewGroup, true);
                }
            }
        });

} // onCreate


    //comm Visible or Invisivle check

    private boolean CommShown() {
        return comm_layout.getVisibility() == View.VISIBLE;
    }

    //Comm Open and disable rear view
    public static void enableDisableViewGroup(ViewGroup viewGroup, boolean enabled) {
        int childCount = viewGroup.getChildCount();
        for (int i = 0; i < childCount; i++) {


            View view = viewGroup.getChildAt(i);
            view.setEnabled(enabled);

            if (view instanceof ViewGroup) {
                enableDisableViewGroup((ViewGroup) view, enabled);
            }
        }
   }
}

xml代码


<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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="match_parent"
    android:background="@android:color/black">


    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/viewGroup"
        android:layout_width="match_parent"
        android:layout_height="match_parent">


        <VideoView
            android:id="@+id/videoView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <ImageView
            android:id="@+id/playimg"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:visibility="invisible"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:srcCompat="@android:drawable/ic_media_play" />


            <ImageView
                android:id="@+id/comm"
                android:layout_width="50dp"
                android:layout_height="50dp"
                app:srcCompat="@android:drawable/sym_def_app_icon"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent" />

    </androidx.constraintlayout.widget.ConstraintLayout>


    <LinearLayout
        android:id="@+id/comm_layout"
        android:layout_width="match_parent"
        android:layout_height="500dp"
        android:orientation="vertical"
        android:background="@color/white"
        android:visibility="invisible"
        app:layout_constraintBottom_toBottomOf="parent">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="30dp">

            <ImageButton
                android:id="@+id/comm_close"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@color/transparent"
                app:srcCompat="@android:drawable/btn_dialog"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintBottom_toBottomOf="parent"/>

        </androidx.constraintlayout.widget.ConstraintLayout>

        <androidx.recyclerview.widget.RecyclerView
            android:layout_width="match_parent"
            android:layout_height="430dp" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <EditText
                android:id="@+id/editText"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="9"
                android:ems="10"
                android:inputType="textPersonName"
                android:hint="comment" />

            <ImageButton
                android:id="@+id/imageButton2"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                app:srcCompat="@android:drawable/sym_def_app_icon" />
        </LinearLayout>
    </LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

头脑

bottom_up.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:fromYDelta="100%p"
        android:toYDelta="0%p"
        android:fillAfter="true"
        android:duration="500" />
</set>


bottom_down.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:fromYDelta="0%p"
        android:toYDelta="70%p"
        android:fillAfter="true"
        android:interpolator="@android:anim/linear_interpolator"
        android:duration="500" />
</set>

我很抱歉我不擅长英语。并感谢您的帮助。

bhavya_karia

要从屏幕底部向上滑动布局,您可以使用Android 提供的BottomSheet

对于底部布局中的键盘隐藏编辑文本,您可以在此处查看这篇文章

我希望它有帮助!

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Facebook Paper-如何向上滑动以缩放底部的UIScrollView

从底部拉出/向上滑动div?

颤振底部容器向上滑动

在Bootstrap 4中从底部向上滑动的模态

Android滑动刷新布局向上滚动以刷新

将布局滑动到屏幕中间(向上滑动),然后向上或向下滑动

Android:如何向上滑动片段?

HTML CSS / JS底部导航栏向上滑动

如何在不向下推视图/窗口小部件的情况下向上滑动(打开)隐藏的textview /布局?

从底部滑动视图在另一个布局上

如何使元素平滑地向上滑动页面?

如何使用slidedown和jquery向上滑动

如何创建向上/向下滑动的 UITableView?

离子2:如何从底部制作滑动菜单

如何从底部到顶部滑动divs

如何在窗口底部固定一个包含灵活高度菜单的选项卡,并使用jQuery在单击时向上滑动?

如何使用ViewPager滑动xml布局

在android上。如何从滑动布局设置墙纸?

就当上向上滑动,Safari浏览器的ios页面底部空白

iPhone X向上滑动以切换应用程序会激活屏幕底部的按钮

从iPhone X iOS 12的底部边缘向上滑动时,停止应用程序进入后台

如何在android中获取布局的底部?

向上滑动面板布局侦听器实现。次要版面可见性问题

使用滑动手势+ SwipeRefreshLayout + RecyclerView的运动布局错误行为向上滚动

如何在android上实现用户“向上滑动显示”

如何使用AutoLayout为向上滑动UIView设置动画?

隐藏上方的网格时,如何向上滑动网格?

如何像里程表一样向上滑动

单击时如何停止下拉菜单子向上滑动