Created
April 7, 2015 20:17
-
-
Save ookami-kb/acab8aad4ed26ba0fff5 to your computer and use it in GitHub Desktop.
DrawerListView with width by Material design guidelines
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DrawerListView(context: Context, attrs: AttributeSet) : ListView(context, attrs) { | |
val widthCalculated : Int | |
init { | |
val displayMetrics = getContext().getResources().getDisplayMetrics() | |
val maxWidth = Math.round(400 * displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT) | |
val wm = getContext().getSystemService(Context.WINDOW_SERVICE) as WindowManager | |
val size = Point() | |
wm.getDefaultDisplay().getSize(size) | |
val windowWidth = size.x | |
val styledAttrs = getContext().getTheme().obtainStyledAttributes(intArray(android.R.attr.actionBarSize)) | |
val abSize = styledAttrs.getDimension(0, 0f) | |
styledAttrs.recycle() | |
widthCalculated = Math.min((windowWidth - abSize).toInt(), maxWidth) | |
} | |
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { | |
super.onMeasure(View.MeasureSpec.makeMeasureSpec(widthCalculated, View.MeasureSpec.EXACTLY), heightMeasureSpec) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment