Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic Row header #384

Open
mnallamalli97 opened this issue Jun 9, 2021 · 1 comment
Open

Dynamic Row header #384

mnallamalli97 opened this issue Jun 9, 2021 · 1 comment

Comments

@mnallamalli97
Copy link

@evrencoskun
Frustrated that I cannot have the row header width be the largest width in my list of strings. I am getting ellipses on all my row headers since one header is much longer than the static row header dimens.

Could you please show solution for row header to be width of longest item in list.

@Eugeniydak
Copy link

You can calculate max width of your RowHeaders:

private fun getMaxWidth(rowHeaderList: List<RowHeaderData>): Int {
    return rowHeaderList.maxOf {
        it.shortName.getTextWidth(16f, 10f)
    }
}

fun String.getTextWidth(textSize: Float, extraWidth: Float): Int {
    val paint = Paint()
    paint.textSize = textSize
    val systemScale = resources.configuration.fontScale
    val density = resources.displayMetrics.density
    return ((paint.measureText(this) + extraWidth) * systemScale * density).toInt()
}

And then set this value to TableView:
updateRowHeaderWidth(getMaxWidth(rowHeaderList))

fun updateRowHeaderWidth(rowHeaderWidth: Int) {
     tableView.rowHeaderWidth = rowHeaderWidth
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants