Reputation: 111
Is there a way I can align the GridView at the bottom of the LinearLayout? I want to position (marginTop) the GridView according to the layout above it, not the top of the screen. Below is my code. Thanks
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:background="@drawable/app_background">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<ImageView
android:id="@+id/begin_tour"
android:layout_width="fill_parent"
android:layout_height="140dp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="@drawable/begin_tour_i"
android:scaleType="centerCrop" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:orientation="horizontal"
android:layout_marginTop="160dp" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<GridView
android:id="@+id/gridview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:verticalSpacing="0dp"
android:horizontalSpacing="0dp"
android:stretchMode="columnWidth"
android:numColumns="2"
android:background="@drawable/grid_border"/>
</FrameLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:baselineAligned="true"
android:orientation="vertical"
android:layout_marginTop="0dp"
android:layout_alignParentBottom="true" >
<TextView
android:id="@+id/link_to_page_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="5"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:textColor="#000000"
android:textStyle="bold"
android:textSize="20dip"
android:textIsSelectable="true" />
</LinearLayout>
</RelativeLayout>
Upvotes: 0
Views: 4321
Reputation: 2911
I think you should use a relative layout.
If you have a relative layout that fills the whole screen you should be able to use android:layout_alignParentTop
to move the Gridview
to the top of the layout.
EDIT:
Try this with a layout_above
.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:background="@drawable/app_background">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<ImageView
android:id="@+id/begin_tour"
android:layout_width="fill_parent"
android:layout_height="140dp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="@drawable/begin_tour_i"
android:scaleType="centerCrop" />
</LinearLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
// HERE
android:layout_alignParentTop="true"
android:layout_above="@+id/botlayout"
android:layout_marginTop="160dp" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<GridView
android:id="@+id/gridview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:verticalSpacing="0dp"
android:horizontalSpacing="0dp"
android:stretchMode="columnWidth"
android:numColumns="2"
android:background="@drawable/grid_border"/>
</FrameLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
// HERE
android:id="@+id/botlayout"
android:baselineAligned="true"
android:layout_marginTop="0dp"
android:layout_alignParentBottom="true" >
<TextView
android:id="@+id/link_to_page_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="5"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:textColor="#000000"
android:textStyle="bold"
android:textSize="20dip"
android:textIsSelectable="true" />
</RelativeLayout>
</RelativeLayout>
Upvotes: 1
Reputation: 71
Just do a relative layout. If you need it above the TextView
, then just do android:layout_above
. Make sure its using id then put in the id for the TextView
. This should put it right above the TextView
. If you need a margin just put one in.
Upvotes: 1