Child View ignoring Parent Layout which holds Nested Layouts, but uses them instead

I have a spinner which is in the parent layout, which holds the Spinner, and nested Relative layouts. The problem I am having is that I cannot seem to get the Spinner to align to this parent layout, even when I specify to align in parent, it still aligns to a nested view.

To clarify: My Spinner is being aligned to the top left of "relativeone", not "back_layout".

Any ideas?

Relevant XML code:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/back_layout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#000000"
    android:gravity="center"
    >

    <Spinner
        android:id="@+id/spinner"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:background="#FFFFFF"
        android:entries="@array/spinner"
        android:layout_alignLeft="@+id/relativeone" />

    <RelativeLayout
        android:id="@+id/relativeone"
        android:layout_width="300dp"
        android:layout_height="300dp"
        android:layout_gravity="center" 
        android:gravity="center">

        <RelativeLayout
            android:id="@+id/relativetwo"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_gravity="center"
            android:gravity="center" >

            <ImageView
                android:id="@+id/imageview"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_alignParentLeft="true"
                android:layout_alignParentTop="true"
                android:layout_gravity="center"
                android:scaleType="fitXY" />

            <Button
                android:id="@+id/buttonone"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true"
                android:text="Take Photo" />
        </RelativeLayout>
    </RelativeLayout>

</RelativeLayout>

Answers


You need to make some minor changes to your properties to make it work.

Drop the center align from back_layout, drop the align left from the spinner, and add center in parent to relativeone.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/back_layout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#000000" >
    <Spinner
        android:id="@+id/spinner1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" />
    <RelativeLayout
        android:id="@+id/relativeone"
        android:layout_width="300dp"
        android:layout_height="300dp"
        android:layout_centerInParent="true"
        android:layout_gravity="center"
        android:gravity="center" >
        <RelativeLayout
            android:id="@+id/relativetwo"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_gravity="center"
            android:gravity="center" >
            <ImageView
                android:id="@+id/imageview"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_alignParentLeft="true"
                android:layout_alignParentTop="true"
                android:layout_gravity="center"
                android:scaleType="fitXY" />
            <Button
                android:id="@+id/buttonone"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true"
                android:text="Take Photo" />
        </RelativeLayout>
    </RelativeLayout>
</RelativeLayout>

Tha above layout will give you this:


Need Your Help

Add a job step in SQL Server 2005

sql sql-server-2005

I have a questions about creating a SQL Job. Can somebody please let me know that how we can

android: Facebook SDK AsyncTask error

java android facebook android-asynctask

This problem has been haunting me down. I have spend enormous time to solve this issue but failed. First of all I am using latest SDK (version 22).

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.