Question

I am very novice to android and trying to add a ImageButton at specific position of my first android app but i am getting image rectangular box start from the start of the screen whereas my button image is at right place ..Here is my code..

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/pnr_bg"
android:orientation="vertical"
android:padding="0dp" >

<ImageButton
    android:id="@+id/imageButton1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingLeft="50dp"
    android:paddingTop="100dp"
    android:src="@drawable/normal" />

Why is this rectangular box visible from the start of the application screen .Please help me..

Was it helpful?

Solution

Since u r using LinearLayoutit fill from the Top to bottom so if u have one View inside the Laytout, it will be at the Top of the Application Screen. in order to use Relative location on the Screen change the LinearLayoutto RelativeLayout

here is an Example :

Button Center Screen

instand of using

android:paddingLeft="50dp" 
android:paddingTop="100dp" 

use

android:layout_marginLeft="50dp" 
android:layout_marginTop="100dp" 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top