RelativeLayout alignParentBottom DialogFragment Listview
I havent done android programming until recently so i havent stumble on anything that i could blog about (plus stackoverflow has the answer to almost everything :] ). I was trying to recreate how Google+ did the new post dialog, in my head i could use DialogFragment and RelativeLayout where i stick the action row to the bottom via alignParentBottom and an EditText on top with layout_below the action layout. But this has a problem, DialogFragment and alignParentBottom dont play along really well as it would just align the action layout to the bottom of the screen regardless of the onscreen keyboard.
Now there are some suggestion where you extends RelativeLayout and compute for the keyboard size and resize the RelativeLayout Here in stackoverflow, but i recently found that adding a listview with layout_below the actionbar would cause the parent to recompute the child layout. Now this might be a bug or its just how RelativeLayout is done since its quite complicated do the calculation. I tested it on 4.4.2 on nexus 5 and 7, 4.3.1 on cm 10.2 on xperia z, 4.3 on xiaomi mi3 and nexus 7 2012, 4.1.2 on xperia acro s, 4.0.3 Star N8000. I cant seem to find a phone lying around thats 4.2 but its safe to assume it would also work.
Now there are some suggestion where you extends RelativeLayout and compute for the keyboard size and resize the RelativeLayout Here in stackoverflow, but i recently found that adding a listview with layout_below the actionbar would cause the parent to recompute the child layout. Now this might be a bug or its just how RelativeLayout is done since its quite complicated do the calculation. I tested it on 4.4.2 on nexus 5 and 7, 4.3.1 on cm 10.2 on xperia z, 4.3 on xiaomi mi3 and nexus 7 2012, 4.1.2 on xperia acro s, 4.0.3 Star N8000. I cant seem to find a phone lying around thats 4.2 but its safe to assume it would also work.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/editTxt"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="Write something"
android:gravity="top|left"
android:layout_above="@+id/actionLayout"
/>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/actionLayout"
/>
<LinearLayout
android:id="@+id/actionLayout"
android:layout_width="wrap_content"
android:layout_height="52dp"
android:layout_alignParentBottom="true"
>
</LinearLayout>
</RelativeLayout>
No comments: