Green Ho
Green Ho

Reputation: 901

Android: Align views vertically left

I'm trying to align some text views vertically left but it doesn't work properly, could anyone else point me out what's wrong with my code below?

 <RelativeLayout
    android:id="@+id/footer"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity = "left"
    android:paddingTop="@dimen/top_spacing"
    android:paddingBottom="@dimen/bottom_spacing"
    android:orientation="vertical"
>
    <TextView
        android:id="@+id/Text1"
        style="@style/style1"
        android:ellipsize="marquee"
        android:marqueeRepeatLimit="marquee_forever"
        android:layout_alignParentLeft="true"
        />

    <TextView
        android:id="@+id/Text2"
        style="@style/style1"
        android:ellipsize="marquee"
        android:marqueeRepeatLimit="marquee_forever"
        android:layout_alignParentLeft="true"
        />

      <TextView
        android:id="@+id/Text3"
        style="@style/style1"
        android:ellipsize="marquee"
        android:marqueeRepeatLimit="marquee_forever"
        android:layout_alignParentLeft="true"
        />
</RelativeLayout>

Upvotes: 0

Views: 435

Answers (3)

TronicZomB
TronicZomB

Reputation: 8747

Try the following:

 <RelativeLayout
android:id="@+id/footer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity = "left"
android:paddingTop="@dimen/top_spacing"
android:paddingBottom="@dimen/bottom_spacing"
android:orientation="vertical"
>
<TextView
    android:id="@+id/Text1"
    style="@style/style1"
    android:ellipsize="marquee"
    android:marqueeRepeatLimit="marquee_forever"
    android:layout_alignParentLeft="true"
    />

<TextView
    android:id="@+id/Text2"
    style="@style/style1"
    android:ellipsize="marquee"
    android:marqueeRepeatLimit="marquee_forever"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/Text1"
    />

  <TextView
    android:id="@+id/Text3"
    style="@style/style1"
    android:ellipsize="marquee"
    android:marqueeRepeatLimit="marquee_forever"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/Text2"
    />

You never set the layout_below attribute. This answer is useful if you choose to use the RelativeLayout, or need to, otherwise you would probably be better off using Neoh's and Fahad Ishaque's answers which pretty much say the same thing.

Upvotes: 1

Fahad Ishaque
Fahad Ishaque

Reputation: 1926

Replace relative layout with linear layout. Your using all the attributes of a linear layout e.g orientation. And please remove nu-necessary tags that belongs to relative layout scheme from the text views.

Upvotes: 1

Neoh
Neoh

Reputation: 16164

It is better to use LinearLayout for your usecase:

<LinearLayout
android:id="@+id/footer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity = "left"
android:gravity="left"
android:paddingTop="@dimen/top_spacing"
android:paddingBottom="@dimen/bottom_spacing"
android:orientation="vertical">
<TextView
    android:id="@+id/Text1"
    style="@style/style1"
    android:ellipsize="marquee"
    android:marqueeRepeatLimit="marquee_forever"
    />

<TextView
    android:id="@+id/Text2"
    style="@style/style1"
    android:ellipsize="marquee"
    android:marqueeRepeatLimit="marquee_forever"
    />

  <TextView
    android:id="@+id/Text3"
    style="@style/style1"
    android:ellipsize="marquee"
    android:marqueeRepeatLimit="marquee_forever"
    />
</LinearLayout>

Upvotes: 1

Related Questions