Vahag Vardanyan
Vahag Vardanyan

Reputation: 301

android move button

I want create activity, and put buttons on any position of screen.

But I can't figure out how to do that.

For example:

<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout android:id="@+id/linearLayout1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android">
        <Button android:text="start" android:layout_height="wrap_content" android:layout_gravity="bottom|center" android:layout_width="wrap_content"></Button>
    </LinearLayout>

In this case button apears in the bottom of screen. But I want button to be a little higher.But I can't. So is there any method to put buttons on the screen using coordinates or anything else?

Upvotes: 2

Views: 8196

Answers (4)

Randroid
Randroid

Reputation: 3698

You can use the following:

android:layout_marginTop= ""

Upvotes: 0

Arnab Chakraborty
Arnab Chakraborty

Reputation: 7472

Try out FrameLayout

Edit: From the site:

FrameLayout is the simplest type of layout object. It's basically a blank space on your screen that you can later fill with a single object — for example, a picture that you'll swap in and out. All child elements of the FrameLayout are pinned to the top left corner of the screen; you cannot specify a different location for a child view. Subsequent child views will simply be drawn over previous ones, partially or totally obscuring them (unless the newer object is transparent).

Upvotes: 1

Sumit
Sumit

Reputation: 746

Use relative layout and within that linear layout.

<RelativeLayout>
.....
<LinearLayout>
.....
</LinearLayout>
</RelativeLayout>

And use margin attribute.

android:layout_marginTop
android:layout_marginRIght
android:layout_marginBottom
android:layout_marginLeft

In your case..

android:layout_marginBottom="40dp"

you can provide the value as you need.

Upvotes: 1

user874649
user874649

Reputation:

Try adding android:layout_marginBottom="10dp" to the button. Like this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/linearLayout1" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
xmlns:android="http://schemas.android.com/apk/res/android">
<Button android:text="start" 
    android:layout_height="wrap_content" 
    android:layout_gravity="bottom|center" 
    android:layout_width="wrap_content"
    android:layout_marginBottom="10dp"></Button>
</LinearLayout>

Upvotes: 4

Related Questions