1

I'm just wasting time with this, because I have no idea how to do it properly. Basically, I want to have a custom input view, where the user can draw whatever he wants with his / her finger and, below it, I want to place 2 (or maybe more) buttons, which I don't want to overlap on top of the custom view. Because I'm trying to avoid hardcoding widths and heights, is there any way to specify that the buttons should wrap to their contents and the custom view should occupy the remaining height? Since I expect all buttons to have the same height, I guess that taking the height of one of them as a reference should work somehow...

Here's my current layout:

<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"
    tools:context=".MainActivity" >

    <com.example.myapp.DrawView
        android:id="@+id/drawView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" />

    <Button
        android:id="@+id/buttonSave"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:text="@string/save" />

    <Button
        android:id="@+id/buttonQuery"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:text="@string/query" />

</RelativeLayout>

Is it actually possible to achieve what I want easily, without having to hack it in nasty ways?

Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
Mihai Todor
  • 8,014
  • 9
  • 49
  • 86

2 Answers2

1

Place the custom view above the Buttons:

<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"
    tools:context=".MainActivity" >

   <Button
        android:id="@+id/buttonSave"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:text="@string/save" />

    <Button
        android:id="@+id/buttonQuery"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:text="@string/query" />

    <com.example.myapp.DrawView
        android:id="@+id/drawView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" 
        android:layout_above="@id/buttonSave" />

</RelativeLayout>

If you aren't sure about the height of the Buttons being equal you would have to wrap them in another layout(like LinearLayout) and then place the custom View above that wrapper.

user
  • 86,916
  • 18
  • 197
  • 190
  • Cool dude, that did the trick! I'd give you a +10 if I could! :) – Mihai Todor Jul 31 '12 at 13:09
  • If you want to avoid declaring the Buttons ahead of the DrawView @Mihai Todor, you can instead declare those ids in a `res/values/ids.xml` file. That way, the order in which you declare the buttons/drawview won't matter at all. The ids already exist external to the layout file. – scriptocalypse Nov 13 '13 at 19:01
0

Place buttons on some layout:

<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"
tools:context=".MainActivity" >

<com.example.myapp.DrawView
    android:id="@+id/drawView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true" />


    <RelativeLayout android:id="@+id/button_layout"
              ........  
              android:layout_alignParentBottom="true"
    >
              ....
              your buttons
              .....
    </RelativeLayout>  
</RelativeLayout>
Vyacheslav Shylkin
  • 9,741
  • 5
  • 39
  • 34
  • But if I set `android:layout_height="match_parent"`, then the custom view will go underneath the buttons, which is just what I'm trying to avoid... – Mihai Todor Jul 31 '12 at 13:04