Results 1 to 2 of 2
  1. #1
    ralph is offline Member
    Join Date
    Nov 2012
    Posts
    36
    Rep Power
    0

    Default Using layout_weight with a relative layout?



    I'm wanting this exact layout, with an image as the top segment, and a text field and send button in the bottom 2 fields respectively.

    I've done this using a relative_layout but the text field grows bigger when typing a message and can make the button to squashed to see.

    With the linear_layout there was a layout_weight to stop this happening (i'd like to give them 70%, 30% of the width respectively)

    How do i go about doing this with a relative layout?

    Thank you

    Java Code:
    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:paddingLeft="16dp"
        android:paddingRight="16dp"
        tools:context=".MainActivity"
        >
        
            <ImageView
                android:id="@+id/test_image"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:contentDescription="@string/test"
                android:src="@drawable/guess_two"
                />
    		    
    		    <EditText
    		        android:id="@+id/edit_message"
    		        android:layout_width="wrap_content"
    		        android:layout_height="wrap_content"
    		        android:layout_alignParentLeft="true"
    		        android:layout_below="@id/test_image"
    		        android:hint="@string/edit_message"
    		         />
    
    		    <Button
    		        android:layout_width="wrap_content"
    		        android:layout_height="wrap_content"
    		        android:layout_alignParentRight="true"
    		        android:layout_below="@id/test_image"
    		        android:layout_toRightOf="@id/edit_message"
    		        android:minWidth="20dp"
    		        android:onClick="sendMessage"
    		        android:text="@string/button_send" />
        
        </RelativeLayout>

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Using layout_weight with a relative layout?

    With the linear_layout there was a layout_weight to stop this happening (i'd like to give them 70%, 30% of the width respectively)
    So put the EditText and the Button within a LinearLayout (nested within the RelativeLayout). At the moment you say the EditText's width should wrap the control's contents so it will do exactly that.

Similar Threads

  1. Grid Layout change layout alignment of control s
    By rellicott in forum SWT / JFace
    Replies: 1
    Last Post: 02-13-2012, 05:11 PM
  2. FileInputStream with relative path in a JAR
    By Bertieboy7 in forum New To Java
    Replies: 3
    Last Post: 03-31-2011, 04:10 AM
  3. How to use a relative path for a file?
    By kipade in forum SWT / JFace
    Replies: 0
    Last Post: 02-28-2011, 06:37 AM
  4. Replies: 2
    Last Post: 10-14-2009, 05:47 AM
  5. how to set relative path in jsp?
    By makpandian in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 01-02-2009, 08:20 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •