I want to set margin to my main layout with programmatically. I use layout params as following code.
val parMain = mainLayout?.layoutParams as ConstraintLayout.LayoutParams
But i have some error like
android.view.ViewGroup$LayoutParams cannot be cast to androidx.constraintlayout.widget.ConstraintLayout$LayoutParams
if I change the code as Android wants like this:
val parMain = mainLayout?.layoutParams as ViewGroup.LayoutParams
There is no set margin function in my layoutParams.
Thats my 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:id="@+id/detail_feed_scrool_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/transparent"
tools:context=".DetailActivity">
<View
android:id="@+id/shadow_view"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:background="#99000000"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.viewpager.widget.ViewPager
android:id="@+id/detail_feed_view_pager_activity"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
</androidx.viewpager.widget.ViewPager>
<FrameLayout
android:id="@+id/detail_fragment_frame_layout"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@android:color/white"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
</FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
How can i set margin in my case?