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

前端 未结 4 1498
灰色年华
灰色年华 2021-02-13 15:40

When I use a RelativeLayout with either fill_parent or wrap_content as height and an element which specifies: android:layout_alignPa

相关标签:
4条回答
  • 2021-02-13 16:17

    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.

    0 讨论(0)
  • 2021-02-13 16:22

    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);
    
    0 讨论(0)
  • 2021-02-13 16:25

    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 讨论(0)
  • 2021-02-13 16:34

    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.

    0 讨论(0)
提交回复
热议问题