Raynold
Raynold

Reputation: 443

How to display this button in center?

This is my .xml file's code,

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/submit_clip"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="center"
    android:background="@android:color/transparent"
    android:scrollbarStyle="insideOverlay"
    android:scrollbars="vertical" >

    <TableLayout
        android:id="@+id/table1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="center"
        android:stretchColumns="*" >

        <TableRow
            android:id="@+id/row1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:gravity="center" >

            <RelativeLayout
                android:id="@+id/left_layout"
                android:layout_width="match_parent"
                android:layout_height="fill_parent"
                android:orientation="vertical" >

                <SeekBar
                    android:id="@+id/seekBar1"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"

                    android:layout_marginLeft="20dp"
                    android:layout_marginRight="20dp"
                    android:layout_marginTop="20dp" />

                <Button
                    android:id="@+id/cmdConfirm"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="20dp"
                    android:layout_below="@+id/seekBar1"
                    android:gravity="center"
                    android:text="Confirm and Proceed" />

                <Button
                    android:id="@+id/txtCancel"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/cmdConfirm"
                    android:gravity="center"
                    android:text="Cancel" />

                </RelativeLayout>

            <RelativeLayout
                android:id="@+id/right_layout"
                android:layout_width="match_parent"
                android:layout_height="fill_parent"
                 >

                <TextView
                    android:id="@+id/txtTitle"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="20dp"
                    android:text="Clip Detail"
                    android:textStyle="bold" />

                <TextView
                    android:id="@+id/txtUnderline"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="20dp"
                    android:layout_below="@+id/txtTitle"
                    android:text="___________________"
                    android:textStyle="bold" />                

                <TextView
                    android:id="@+id/txtName"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="20dp"
                    android:layout_below="@+id/txtUnderline"
                    android:text="Name : " />          

                <TextView
                    android:id="@+id/txtDescription"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="20dp"
                    android:layout_below="@+id/txtName"
                    android:text="Description : " />                

                <TextView
                    android:id="@+id/txtCategory"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="20dp"
                     android:layout_below="@+id/txtDescription"
                    android:text="Category : "/>                

                <TextView
                    android:id="@+id/txtClipType"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="20dp"
                     android:layout_below="@+id/txtCategory"
                    android:text="Clip Type : "/>                

                <TextView
                    android:id="@+id/txtDuration"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="20dp"
                     android:layout_below="@+id/txtClipType"
                    android:text="Duration : "/>                

                <TextView
                    android:id="@+id/txtArtist"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="20dp"
                     android:layout_below="@+id/txtDuration"
                    android:text="Artist : "/>                

                <TextView
                    android:id="@+id/txtSoundTrack"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="20dp"
                     android:layout_below="@+id/txtArtist"
                    android:text="Sound Track : "/>                


                </RelativeLayout>
        </TableRow>
    </TableLayout>

</ScrollView>

It shows output as following image,

enter image description here

As you can see in the image that both command buttons are placed on the left side, i want to change their location to center like below image,

enter image description here

So how can i change their location to center ?

Upvotes: 0

Views: 685

Answers (2)

MuraliGanesan
MuraliGanesan

Reputation: 3259

Try this, Use linear for each Button and give for it `gravity="center"

 <?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/submit_clip"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:background="@android:color/transparent"
android:scrollbarStyle="insideOverlay"
android:scrollbars="vertical" >

<TableLayout
    android:id="@+id/table1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="center"
    android:stretchColumns="*" >

    <TableRow
        android:id="@+id/row1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="center" >

        <RelativeLayout
            android:id="@+id/left_layout"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:gravity="center"
            android:orientation="vertical" >

            <SeekBar
                android:id="@+id/seekBar1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="20dp"
                android:layout_marginRight="20dp"
                android:layout_marginTop="20dp" />

            <LinearLayout
                android:id="@+id/conform_linear"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/seekBar1" >

                <Button
                    android:id="@+id/cmdConfirm"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:text="Confirm and Proceed" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/conform_linear"
                android:gravity="center" >
            </LinearLayout>

            <Button
                android:id="@+id/txtCancel"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true"
                android:text="Cancel" />
        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/right_layout"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >

            <TextView
                android:id="@+id/txtTitle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="20dp"
                android:text="Clip Detail"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/txtUnderline"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/txtTitle"
                android:layout_marginLeft="20dp"
                android:text="___________________"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/txtName"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/txtUnderline"
                android:layout_marginLeft="20dp"
                android:text="Name : " />

            <TextView
                android:id="@+id/txtDescription"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/txtName"
                android:layout_marginLeft="20dp"
                android:text="Description : " />

            <TextView
                android:id="@+id/txtCategory"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/txtDescription"
                android:layout_marginLeft="20dp"
                android:text="Category : " />

            <TextView
                android:id="@+id/txtClipType"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/txtCategory"
                android:layout_marginLeft="20dp"
                android:text="Clip Type : " />

            <TextView
                android:id="@+id/txtDuration"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/txtClipType"
                android:layout_marginLeft="20dp"
                android:text="Duration : " />

            <TextView
                android:id="@+id/txtArtist"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/txtDuration"
                android:layout_marginLeft="20dp"
                android:text="Artist : " />

            <TextView
                android:id="@+id/txtSoundTrack"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/txtArtist"
                android:layout_marginLeft="20dp"
                android:text="Sound Track : " />
        </RelativeLayout>
    </TableRow>
</TableLayout>

Upvotes: 1

Raynold
Raynold

Reputation: 443

I have added following line to both command button and its working fine, the line is

android:layout_centerHorizontal="true"

Upvotes: 3

Related Questions