From 60678debfa474e6b3d5e85b1762ced67bd8ef5cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Borcz?= Date: Fri, 14 Jun 2019 12:11:02 +0200 Subject: [PATCH] Fix left margin in landscape mode --- .../materialchipsinput/DropdownListView.kt | 14 ++++++++------ library/src/main/res/layout/item_dropdown_list.xml | 2 +- sample/src/main/AndroidManifest.xml | 5 ++++- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/library/src/main/java/io/github/wulkanowy/materialchipsinput/DropdownListView.kt b/library/src/main/java/io/github/wulkanowy/materialchipsinput/DropdownListView.kt index c2403b7..80846f7 100644 --- a/library/src/main/java/io/github/wulkanowy/materialchipsinput/DropdownListView.kt +++ b/library/src/main/java/io/github/wulkanowy/materialchipsinput/DropdownListView.kt @@ -15,6 +15,8 @@ import android.view.ViewGroup.LayoutParams.MATCH_PARENT import android.view.ViewTreeObserver import android.view.animation.AlphaAnimation import android.widget.RelativeLayout +import androidx.core.view.marginLeft +import androidx.core.view.updateMargins import androidx.recyclerview.widget.LinearLayoutManager import com.google.android.material.chip.Chip import io.github.wulkanowy.materialchipsinput.util.navBarHeight @@ -95,12 +97,12 @@ internal class DropdownListView @JvmOverloads constructor(context: Context, attr val coordinators = IntArray(2) chipInput.getLocationInWindow(coordinators) - val layoutParams = layoutParams as MarginLayoutParams - layoutParams.topMargin = coordinators[1] + chipInput.height - - layoutParams.bottomMargin = rootView.height - rect.bottom - setLayoutParams(layoutParams) - + (layoutParams as MarginLayoutParams).updateMargins( + top = coordinators[1] + chipInput.height, + bottom = rootView.height - rect.bottom, + left = if (rect.left > 0) rect.left else marginLeft + ) + requestLayout() startAnimation(AlphaAnimation(0.0f, 1.0f).apply { duration = 200 }) visibility = VISIBLE } diff --git a/library/src/main/res/layout/item_dropdown_list.xml b/library/src/main/res/layout/item_dropdown_list.xml index 4730e18..aa520b9 100644 --- a/library/src/main/res/layout/item_dropdown_list.xml +++ b/library/src/main/res/layout/item_dropdown_list.xml @@ -6,7 +6,7 @@ android:background="?attr/selectableItemBackground" android:orientation="horizontal"> - - +