-1

Please have a look at the following code

<ScrollView 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"
    tools:context=".DisplayResult" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_gravity="center"
        android:gravity="center"
        >

        <ImageView
            android:id="@+id/zodiac1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/aries"
            />

        <TextView
            android:id="@+id/orTxt"
            android:text="Or"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"

            />

        <ImageView 
            android:id="@+id/zodiac2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/gemini"
            />

    </LinearLayout>




    </ScrollView>

I want this "LinearLayout" to be centered at the top. Not in the exact center of the device screen. How can I do it? Please help!

EDIT

What I mean is, I want the things inside linear layout to be appeared at the top of the application. They should be centered in that space. If I use RelativeLayout, this is what I do

android:layout_centerHorizontal="true"
android:layout_alignTop="true"
PeakGen
  • 21,894
  • 86
  • 261
  • 463

1 Answers1

2

If you want to duplicate RelativeLayout's alignTop, try:

<ScrollView 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"
    tools:context=".DisplayResult" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:gravity="center_horizontal" >
Sam
  • 86,580
  • 20
  • 181
  • 179
  • 2
    It might be better to use `android:gravity="center_horizontal"`. – Ted Hopp Dec 27 '12 at 20:36
  • The ScrollView contains a LinearLayout set to horizontal, this layout has two ImageViews and a TextView... I'm not certain `"center_horizontal"` will do anything, but it is already included in `"center"`. If Sepala clarifies what s/he wants, I'll happy adjust my answer. – Sam Dec 27 '12 at 20:41
  • @TedHopp: Oh yes.. That's the answer. – PeakGen Dec 27 '12 at 20:50
  • I haven't tried it, but I was thinking that if gravity was `center` and the child was shorter than the scroll view, the linear layout would be centered vertically as well as horizontally. OP specifically said that the child should be centered at the top. – Ted Hopp Dec 27 '12 at 22:03