Skip to content

Commit efb0872

Browse files
committed
Optimized calculating height and getting rid of app:fullHeight="true"
1 parent d2e6387 commit efb0872

6 files changed

Lines changed: 14 additions & 32 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ implementation 'com.github.Stjinchan:ExpandableCardView:1.1.2'
3232

3333
### Beta
3434
```gradle
35-
implementation 'com.github.Stjinchan:ExpandableCardView:1.2.0-beta01'
35+
implementation 'com.github.Stjinchan:ExpandableCardView:1.2.0-beta05'
3636
```
3737

3838
```
39-
This is a beta, introducing ```app:fullHeight``` as a workaround for the [Innerview issue](https://github.com/AleSpero/ExpandableCardView/issues/9)
40-
I hope to fix this in the future and might remove this attribute
39+
This is a beta, introducing a different way of calculating inner_view height as a fix for the [Innerview issue](https://github.com/AleSpero/ExpandableCardView/issues/9)
40+
I am still testing if this works as intended
4141
```
4242

4343
Or get the aar in the [Releases](https://github.com/Stjinchan/ExpandableCardView/releases) section.

app/src/main/res/layout/activity_main.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@
108108
android:layout_marginRight="20dp"
109109
android:layout_marginBottom="10dp"
110110
app:animationDuration="900"
111-
app:fullHeight="true"
112111
app:expandOnClick="true"
113112
app:icon="@drawable/ic_dates"
114113
app:inner_view="@layout/test"

app/src/main/res/layout/test.xml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:app="http://schemas.android.com/apk/res-auto"
23
android:id="@+id/expand_card_root"
34
android:layout_width="match_parent"
45
android:layout_height="match_parent">
@@ -17,16 +18,8 @@
1718
android:layout_height="wrap_content"
1819
android:layout_below="@id/module_always_on_display_CardText"
1920
android:layout_alignParentEnd="true"
20-
android:layout_alignParentBottom="false"
21+
android:layout_alignParentBottom="true"
2122
android:layout_marginEnd="16dp" />
2223

23-
<com.google.android.material.switchmaterial.SwitchMaterial
24-
android:id="@+id/card_module_always_on_display_enable_switch1"
25-
android:layout_width="wrap_content"
26-
android:layout_height="wrap_content"
27-
android:layout_below="@id/card_module_always_on_display_enable_switch"
28-
android:layout_alignParentEnd="true"
29-
android:layout_alignParentBottom="false"
30-
android:layout_marginEnd="16dp" />
3124

3225
</RelativeLayout>

expandablecardview/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ apply plugin: 'kotlin-android-extensions'
55
ext {
66
PUBLISH_GROUP_ID = 'host.stjin'
77
PUBLISH_ARTIFACT_ID = 'expandable-cardview'
8-
PUBLISH_VERSION = '1.2.0-beta04'
8+
PUBLISH_VERSION = '1.2.0-beta05'
99
}
1010

1111
android {
@@ -14,7 +14,7 @@ android {
1414
defaultConfig {
1515
minSdkVersion 18
1616
targetSdkVersion 29
17-
versionCode 9
17+
versionCode 10
1818
versionName PUBLISH_VERSION
1919

2020
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

expandablecardview/src/main/java/host/stjin/expandablecardview/ExpandableCardView.kt

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ class ExpandableCardView @JvmOverloads constructor(context: Context, attrs: Attr
6262
private var cardRadius: Float = 4f
6363
private var cardElevation: Float = 4f
6464
private var cardRipple: Boolean = false
65-
private var fullHeight: Boolean = false
6665
private var expandableCardTitleBold: Boolean = false
6766
private var iconDrawable: Drawable? = null
6867

@@ -118,7 +117,6 @@ class ExpandableCardView @JvmOverloads constructor(context: Context, attrs: Attr
118117
animDuration = typedArray.getInteger(R.styleable.ExpandableCardView_animationDuration, DEFAULT_ANIM_DURATION).toLong()
119118
startExpanded = typedArray.getBoolean(R.styleable.ExpandableCardView_startExpanded, false)
120119
cardRipple = typedArray.getBoolean(R.styleable.ExpandableCardView_expandableCardRipple, false)
121-
fullHeight = typedArray.getBoolean(R.styleable.ExpandableCardView_fullHeight, false)
122120
expandableCardTitleBold = typedArray.getBoolean(R.styleable.ExpandableCardView_expandableCardTitleBold, false)
123121
cardStrokeColor = typedArray.getInteger(R.styleable.ExpandableCardView_expandableCardStrokeColor, android.R.color.transparent)
124122
cardArrowColor = typedArray.getInteger(R.styleable.ExpandableCardView_expandableCardArrowColor, android.R.color.black)
@@ -184,12 +182,7 @@ class ExpandableCardView @JvmOverloads constructor(context: Context, attrs: Attr
184182
}
185183

186184

187-
val targetHeight = if (fullHeight) {
188-
getFullHeight(card_layout)
189-
} else{
190-
card_layout.measure(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)
191-
card_layout.measuredHeight
192-
}
185+
val targetHeight = getFullHeight(card_layout)
193186

194187
if (targetHeight - initialHeight != 0) {
195188
animateViews(initialHeight,
@@ -214,14 +207,12 @@ class ExpandableCardView @JvmOverloads constructor(context: Context, attrs: Attr
214207
val numberOfChildren = layout.childCount
215208
for (i in 0 until numberOfChildren) {
216209
val child = layout.getChildAt(i)
217-
totalHeight += if (child is ViewGroup) {
218-
getFullHeight(child)
219-
} else {
220-
val desiredWidth = MeasureSpec.makeMeasureSpec(layout.width,
221-
MeasureSpec.AT_MOST)
222-
child.measure(desiredWidth, MeasureSpec.UNSPECIFIED)
223-
child.measuredHeight
224-
}
210+
211+
val desiredWidth = MeasureSpec.makeMeasureSpec(layout.width,
212+
MeasureSpec.AT_MOST)
213+
child.measure(desiredWidth, MeasureSpec.UNSPECIFIED)
214+
child.measuredHeight
215+
totalHeight+=child.measuredHeight
225216
}
226217
layout.visibility = initialVisibility
227218
return totalHeight

expandablecardview/src/main/res/values/attr.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
<attr name="animationDuration" format="integer"/>
1010
<attr name="startExpanded" format="boolean"/>
1111
<attr name="expandableCardRipple" format="boolean"/>
12-
<attr name="fullHeight" format="boolean"/>
1312
<attr name="expandableCardTitleBold" format="boolean"/>
1413
<attr name="expandableCardStrokeWidth" format="integer"/>
1514
<attr name="expandableCardTitleSize" format="float"/>

0 commit comments

Comments
 (0)