Issue
I have a layout to whom I gave a hardcoded height and width. I have plus and minus buttons on layout and trying to increase height and width but it's not working for me. Here is my xml Layout
<androidx.constraintlayout.motion.widget.MotionLayout
android:id="@+id/floating_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/black"
app:layoutDescription="@xml/floating_play_layout_scene">
<VideoView
android:id="@+id/floating_video"
android:layout_width="wrap_content"
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" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/close_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:alpha="0"
android:src="@drawable/float_close"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/float_playbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:alpha="0"
android:src="@drawable/ic_play"
app:layout_constraintBottom_toBottomOf="@id/floating_video"
app:layout_constraintEnd_toEndOf="@id/floating_video"
app:layout_constraintStart_toStartOf="@id/floating_video"
app:layout_constraintTop_toTopOf="@id/floating_video" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/fullscreen_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:alpha="0"
android:src="@drawable/full_screen"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/add_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/_10sdp"
android:layout_marginBottom="@dimen/_10sdp"
android:background="@color/transparent"
android:src="@drawable/ic_add_enabled"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/min_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/_5sdp"
android:layout_marginBottom="@dimen/_10sdp"
android:background="@color/transparent"
android:src="@drawable/ic__remove_enabled"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/add_btn" />
</androidx.constraintlayout.motion.widget.MotionLayout>
this is how I'm increasing height and width dynamically
addbtn.setOnClickListener {
height.plus(10)
width.plus(10)
params = WindowManager.LayoutParams(
width,
height,
LAYOUT_FLAG,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT
)
}
And how I'm assigning these params to window manager
windowManager.addView(mFloatingView, params)
Solution
try this code in your button click event :-
ViewGroup.LayoutParams layoutParams = rel_inc_dec.getLayoutParams();
layoutParams.height = layoutParams.height + 50;
layoutParams.width = layoutParams.width + 50;
rel_inc_dec.setLayoutParams(layoutParams);
Answered By - Milan.Tejani
Answer Checked By - Timothy Miller (JavaFixing Admin)