0

I have a viewPager which I'm attempting to set at the bottom of the screen (along with all other items in the last RelativeLayout) however android:layout_alignParentBottom="true" and android:gravity="bottom" seem to have no affect on RelativeLayout and I'm not sure why.

XML:

<?xml version="1.0" encoding="UTF-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:id="@+id/content_frame"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:focusable="true"
        android:orientation="vertical" >
    </LinearLayout>

    <ListView
        android:id="@+id/left_drawer"
        android:layout_width="220dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@color/darkgrey"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:autoLink="web"
        android:textStyle="bold" />

    <ListView
        android:id="@+id/videosListView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <RelativeLayout
        android:id="@+id/rl"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#AAFFFFFF" >
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/footer"
         android:gravity="bottom"

        android:layout_width="match_parent"
        android:layout_height="50dip"
        android:layout_alignParentBottom="true" >

        <android.support.v4.view.ViewPager
            android:id="@+id/view_pager"
            android:layout_alignParentBottom="true"
             android:layout_weight="1"
            android:layout_width="wrap_content"
            android:layout_height="match_parent" />

        <ImageButton
            android:layout_width="30dip"
            android:layout_height="30dip"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:layout_marginLeft="15dp"
            android:focusable="false"
            android:src="@drawable/scroll_lt_arrow" />

        <ImageButton
            android:layout_width="30dip"
            android:layout_height="30dip"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_marginRight="15dp"
            android:focusable="false"
            android:src="@drawable/scroll_rt_arrow" />
    </RelativeLayout>

</android.support.v4.widget.DrawerLayout>

Source Snippet:

  @Override
    public Object instantiateItem(ViewGroup container, int position) {
        Context context = SAXParserAsyncTaskActivity.this;
        ImageView imageView = new ImageView(context);
    //  imageView.setScaleType(ScaleType.FIT_XY);
        imageView.setImageResource(mImages[position]);
        ((ViewPager) container).addView(imageView, 0);
        return imageView;
    }

Screenshot:

https://i.stack.imgur.com/xyy0c.png

user3311950
  • 5
  • 1
  • 3

1 Answers1

1

The issue with trying to use android:layout_alignParentBottom on your footer RelativeLayout is that the footer layout has no parent.

layout_alignParentBottom and other related attributes that RelativeLayout provides are used to position Views that are children of a RelativeLayout. They cannot be used to position a RelativeLayout inside of its parent unless the RelativeLayout is nested inside a RelativeLayout.

android:gravity doesn't work for what you want because it is used to position a View's children within that View. If you want to set a View to align with the bottom of its parent, you should use android:layout_gravity. See gravity and layout_gravity for more information.

You might also want to read the documentation for DrawerLayout, as I don't think it does quite what you expect. If you only have one drawer, your DrawerLayout should contain only two children- the drawer and the main content (either of which could have child views, but there needs to only be two direct children).

Community
  • 1
  • 1
Bryan Herbst
  • 66,602
  • 10
  • 133
  • 120