Reputation: 25
I am trying to add an image button with an image to my page, but when I load the application; the image button is not appearing.
Does anyone have any advice?
XML:(it is the top image button)
<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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.application.MainActivity$PlaceholderFragment" >
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/listView1"
android:layout_below="@+id/button2"
android:layout_marginRight="34dp"
android:src="@drawable/ic_launcher" />
<EditText
android:id="@+id/edit_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/listView1"
android:layout_alignParentTop="true"
android:ems="10"
android:hint="@string/edit_message"
android:visibility="invisible" />
<EditText
android:id="@+id/txt_Password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/edit_message"
android:layout_below="@+id/edit_message"
android:ems="10"
android:hint="@string/txt_Password"
android:visibility="invisible" >
<requestFocus />
</EditText>
<Button
android:id="@+id/getSelectedItems"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/edit_message"
android:layout_toRightOf="@+id/edit_message"
android:onClick="btnGetSelectedItems_Click"
android:text="@string/getSelectedItemsButton_Message"
android:visibility="invisible" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:onClick="sendMessage"
android:text="@string/button_send" />
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/button1"
android:layout_alignParentLeft="true"
android:layout_alignTop="@+id/edit_message"
android:visibility="invisible" >
</ListView>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/listView1"
android:layout_marginLeft="21dp"
android:layout_toRightOf="@+id/button1"
android:onClick="openOptions"
android:text="Button" />
</RelativeLayout>
Thanks,
Callum
Upvotes: 0
Views: 229
Reputation: 6736
remove the line
android:layout_below="@+id/button2"
from the ImageButton
it is displaying below button and that is why it is outside the visible area.
Upvotes: 4
Reputation: 1642
Give this a try:
<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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.application.MainActivity$PlaceholderFragment" >
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="34dp"
android:src="@drawable/ic_launcher" />
<EditText
android:id="@+id/edit_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/listView1"
android:layout_alignParentTop="true"
android:ems="10"
android:hint="@string/edit_message"
android:visibility="invisible" />
<EditText
android:id="@+id/txt_Password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/edit_message"
android:layout_below="@+id/edit_message"
android:ems="10"
android:hint="@string/txt_Password"
android:visibility="invisible" >
<requestFocus />
</EditText>
<Button
android:id="@+id/getSelectedItems"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/edit_message"
android:layout_toRightOf="@+id/edit_message"
android:onClick="btnGetSelectedItems_Click"
android:text="@string/getSelectedItemsButton_Message"
android:visibility="invisible" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:onClick="sendMessage"
android:text="@string/button_send" />
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/button1"
android:layout_alignParentLeft="true"
android:layout_alignTop="@+id/edit_message"
android:visibility="invisible" >
</ListView>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/listView1"
android:layout_marginLeft="21dp"
android:layout_toRightOf="@+id/button1"
android:onClick="openOptions"
android:text="Button" />
Upvotes: 0