开发者

android:layout_alignParentBottom is ignored when used without explicit layout height as a row in ListView

When I use a RelativeLayout with either fill_parent or wrap_content as height and an element which specifies: android:layout_al开发者_JAVA百科ignParentBottom="true" it is ignored and it is aligned at the top. Setting the height of the RelativeLayout to an explicit value makes it work. Any clues?


This seems to be a bug in Android itself, see http://code.google.com/p/android/issues/detail?id=1394.

I worked around it by wrapping my RelativeLayout in a FrameLayout and putting my bottom aligned view as a children of the FrameLayout with android:layout_gravity="bottom". This hinders you from referencing it from within the RelativeLayout so you'll have to work around that (for example using margins).

If anyone has a better workaround, please share.


When you inflate the layout, use inflate(R.layout.whatever, parent, false), where parent is the ListView. If you don't do that (e.g., you pass null for the parent), RelativeLayout gets strange in list rows.


My hack for this andriod bug:

ViewGroup.LayoutParams lp=(ViewGroup.LayoutParams)view.getLayoutParams();
lp.height=view.getContentHeight();//hack for android bug about ViewGroup.LayoutParams.WRAP_CONTENT and android:layout_alignParentBottom="true" on landscape orientation
view.requestLayout();
act.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);


I was able to get the proper alignment by specifying the problematic TextView with:

android:id="@+id/must_be_bottom_left"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_below="@id/xxx"

where xxx was the id of a TextView that has android:layout_below="@id/yyy"

and yyy is a TextView that is always above both xxx and must_be_bottom_left.

The contents of my list items can vary so that sometimes the "xxx" TextView is View.GONE, but even then the layout works as expected.

I don't know how fragile or merely seredipidous this work-around is. I am using Android 1.6 and I haven't tested it for forward compatability.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜