Android UI Layout Question

I am new to Android programming and have done a lot of searching for the answer to this question however I can not find an answer. Maybe I am using the wrong search terms because it seems like a pretty basic request. I my design (as an example), I would have two text fields defined in my relative layout followed by an image and I would like the image to span the remainder of the screen. Here is what I have so far:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/widget29"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<ImageView
android:id="@+id/widget38"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/widget37"
android:layout_alignParentLeft="true"
>
</ImageView>
<TextView
android:id="@+id/widget37"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="second view"
android:layout_below="@+id/widget36"
android:layout_alignParentLeft="true"
>
</TextView>
<TextView
android:id="@+id/widget36"
android:layout_width="fill_parent"
android:layout_height="50px"
android:text="first view"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
>
</TextView>
</RelativeLayout>

How do I tell my ImageView to span fill the remainder of the screen. If I define the height and width as "fill_parent" it fills over the two text views. Thanks in advance for any help you can provide.

Jon

Answers


It looks like you're just stacking views... it seems to me that this situation would work a lot better with a vertical LinearLayout instead of a RelativeLayout, for one it would be significantly easier to get the image view to span the rest of the space without overlapping your text views:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/widget29"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
>

<TextView
android:id="@+id/widget36"
android:layout_width="fill_parent"
android:layout_height="50px"
android:text="first view"
android:layout_weight="0"
/>

<TextView
android:id="@+id/widget37"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="second view"
android:layout_weight="0"
/>

<ImageView
android:id="@+id/widget38"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
/>
</LinearLayout>

In the above example you use layout weights to force relative sharing of the screen space. Setting the weight to zero forces the layout manager to give only requested space to the two text views and since the image view is set to fill parent (with a weight of 1) it receives all of the remaining space


If it's RelativeLayout, then, you will have to do something like this in your ImageView:

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@id/id_of_your_second_textview"
    android:layout_alignParentRight="true"/>

Need Your Help

Better way to convert dialog from QT Creator and incorporate it into my mainwindow

python pyqt pyqt4 qt-creator

I'm creating a simple popup box that contains settings. I want this to be a modal dialog box. I created the window from qt creator and converted the .ui to .py using pyuic. With the main window i'm...

Best way to implement a Web 2.0 navigation system

php javascript url cookies address-bar

Now here is my situation: I'm making a CMS. When links are clicked, i would like the pages to load dynamically using Ajax. The problem in the links!