Android – how to make a scrollable constraintlayout?

I want to make a layout that lets me scroll down using constraint layout, but I don’t know how to go about it. Should the ScrollView be the parent of the ConstraintLayout like this? <?xml version=”1.0″ encoding=”utf-8″?> <ScrollView 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:layout_width=”match_parent” android:layout_height=”match_parent” android:fillViewport=”true”> <android.support.constraint.ConstraintLayout android:id=”@+id/Constraint” android:layout_width=”match_parent” android:layout_height=”match_parent”/> Or the other way around? Maybe someone … Read more

How to center the content inside a linear layout?

I’m trying to center an ImageView inside a LinearLayout horizontally and vertically, but I just can’t do it. The main reason why I’m not using a RelativeLayout for that is because I need the layout_weight (my Activity consists of four columns that should be equally divided, and also responsive to different screen widths, each column … Read more

Why not use always android:configChanges=”keyboardHidden|orientation”?

I was wondering why not use android:configChanges=”keyboardHidden|orientation” in every (almost every ;)) activity? Goods: no need to worry about your activity been rotated it’s faster Not so nice: need to change your layouts if they are depending on screen size (e.g. layouts with two columns or so) Bad: no flexible way to have different layouts … Read more

Disable soft keyboard on NumberPicker

I’m trying to deactivate the soft keyboard when using a NumberPicker to enter numerical values (for aesthetic reasons). This is my layout-xml-code: <?xml version=”1.0″ encoding=”utf-8″?> <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”match_parent” android:layout_height=”match_parent” android:orientation=”vertical” > <LinearLayout android:id=”@+id/linearLayout2″ android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:layout_gravity=”center_horizontal” android:layout_marginBottom=”30dp” android:layout_marginTop=”30dp” > <NumberPicker android:id=”@+id/repetitionPicker” android:layout_width=”40dp” android:layout_height=”wrap_content” /> <TextView android:id=”@+id/textView1″ android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:layout_gravity=”center_vertical” android:text=”@string/repetitions_short_divider” android:textAppearance=”?android:attr/textAppearanceMedium” /> <NumberPicker android:id=”@+id/weightPicker” android:layout_width=”40dp” … Read more

Android How to adjust layout in Full Screen Mode when softkeyboard is visible

I have researched a lot to adjust the layout when softkeyboard is active and I have successfully implemented it but the problem comes when I use android:theme=”@android:style/Theme.NoTitleBar.Fullscreen” this in my activity tag in manifest file. For this I have used android:windowSoftInputMode=”adjustPan|adjustResize|stateHidden” with different options but no luck. After that I implemented FullScreen programmatically and tried … Read more

How do I make WRAP_CONTENT work on a RecyclerView

I have a DialogFragment that contains a RecyclerView (a list of cards). Within this RecyclerView are one or more CardViews that can have any height. I want to give this DialogFragment the correct height based on the CardViews that are contained within. Normally this would be simple, I would set wrap_content on the RecyclerView like … Read more

Android Paint: .measureText() vs .getTextBounds()

I’m measuring text using Paint.getTextBounds(), since I’m interested in getting both the height and width of the text to be rendered. However, the actual text rendered is always a bit wider than the .width() of the Rect information filled by getTextBounds(). To my surprise, I tested .measureText(), and found that it returns a different (higher) … Read more