Reputation: 49
Click the button to get LinearLayout from the bottom. But there's a problem.
After the layout is finished, the VideoView doesn't work with one click. Works on the second click.
I want to make the layout disappear if I touch anywhere other than the layout on top. (Of course, the VideoView at the rear should not work when clicked.)
If I click EditText, I want to place the EditText and the buttons on the soft keyboard. (It is now obscured by the softkeyboard.)
this is my code.
Java code
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 code
<?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>
anim
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>
I am sorry that I am not good at English. And thank you for your help.
Upvotes: 0
Views: 455
Reputation: 780
For sliding a layout up from the bottom of the screen, you can use BottomSheet provided by Android.
And for keyboard hiding edit text in the bottom layout, you can check out this post here
I hope it helps!
Upvotes: 2