Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have an application were i am trying to align 3 textViews. These are inside a LinearLayout(vertical orientation) which is placed inside a ScrollView.

If I don't use the ScrollView and the LinearLayout I can have all three aligned to each other as one on the left of the screen, and the other 2 to the right.

But when I use the ScrollView and the LinearLayout I can only align them at the bottom and no longer to the right.

can some help me to align these three text views inside the ScrollView ?

this is the code I am using:

<ScrollView
android:layout_width="fill_parent"
android:layout_height="250dp" > 
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="250dp"
        android:orientation="vertical" >

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="40dp"
           android:layout_marginLeft="25dp"
        android:text="one"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/textView2"
        android:layout_alignBottom="@+id/textView2"
        android:layout_marginLeft="25dp"
        android:layout_toRightOf="@+id/textView2"
        android:text="two"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/textView3"
        android:layout_alignBottom="@+id/textView3"
        android:layout_marginLeft="22dp"
        android:layout_toRightOf="@+id/textView3"
        android:text="three"
        android:textAppearance="?android:attr/textAppearanceLarge" />

</LinearLayout> 

i need the code to be something like this:

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/scrollView1"
    android:layout_marginTop="40dp"
    android:text="one"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
    android:id="@+id/textView3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/textView2"
    android:layout_alignBottom="@+id/textView2"
    android:layout_marginLeft="25dp"
    android:layout_toRightOf="@+id/textView2"
    android:text="two"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
    android:id="@+id/textView4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/textView3"
    android:layout_alignBottom="@+id/textView3"
    android:layout_marginLeft="22dp"
    android:layout_toRightOf="@+id/textView3"
    android:text="three"
    android:textAppearance="?android:attr/textAppearanceLarge" />
share|improve this question

2 Answers 2

Use Relative layout instead of LinearLayout. and don't use

android:layout_toRightOf="@+id/textView3"

in liner layout

share|improve this answer

Use RelativeLayout instead of LinearLayout

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.