Reputation: 109
I'm having problems adding a button to my app using relative layout.When I use the graphical layout tool it shows up when i drag and drop the button but when I compile and run the apk on the emulator only the original 'sms' button is there.The new button should of been to the left of the 'sms' button
and here's the code from the xml file
<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="wrap_content"
android:background="#FF000000" >
<EditText
android:id="@+id/edit_message_input"
android:layout_width="match_parent"
android:layout_height="100dp"
android:hint="@string/edit_message_input"
android:inputType="textMultiLine"
android:background="#ff000000"
android:textColor="#CCCCCC"
/>
<Button
android:id="@+id/button2"
android:layout_width="150dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="36dp"
android:text="@string/translate_to_english"
android:onClick="sendToEnglish"
android:background="#CCCCCC"
/>
<Button
android:id="@+id/button1"
android:layout_width="150dp"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="@string/translate_to_text"
android:onClick="sendToText"
android:background="#CCCCCC" />
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:layout_above="@+id/button3"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="31dp"
android:ems="10"
android:hint="@string/edit_message_output"
android:inputType="textMultiLine"
android:background="#ff000000"
android:textColor="#CCCCCC" />
<Button
android:id="@+id/button3"
android:layout_width="150dp"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_alignRight="@+id/button2"
android:layout_marginRight="22dp"
android:background="#CCCCCC"
android:onClick="sendSMS"
android:text="@string/send_as_sms" />
<!-- test save button -->
<Button
android:id="@+id/save_word_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="#cccccc"
android:text="@string/save_word" />
</RelativeLayout>
Any help or pointers much appreciated!
Upvotes: 1
Views: 149
Reputation: 1483
To be honest, I suggest you head over to the android developer docs and spend some time reading the recommendations on designing interfaces.
Two particularly useful sections are:
http://developer.android.com/design/style/metrics-grids.html
and
http://developer.android.com/guide/topics/ui/layout/relative.html
http://developer.android.com/reference/android/widget/RelativeLayout.LayoutParams.html
You have a number of fixed dimensions in your xml and conflicting alignment attributes which appear to be causing a few problems.
Upvotes: 0
Reputation: 128428
Don't assume what ever you design in XML layout will looks nice in every device, because there are wide range of android devices out in market.
Don't take fixed height/width layout if you want to support multiple screens.
android:layout_width="150dp"
android:layout_height="40dp"
Instead, you can mention "wrap_content" or "fill_parent".
Upvotes: 1