10

I got three TextViews. The first and the third are defined with a not changing Text. The second, the TextView between the first and the third gets the value with an input. How can I set the second TextView between the first and the third in the layout?

<TextView
android:id="@+id/secondtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/firsttext"
android:layout_above="@+id/thirdtext"
android:layout_alignLeft="@+id/firsttext"
android:layout_alignRight="@+id/thirdtext"
android:background="@drawable/border"
android:scrollbars="vertical"
android:textAppearance="?android:attr/textAppearanceMedium" />

That doesn't work!

<TextView
        android:id="@+id/secondtext"
        android:layout_width="282dp"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/firsttext"
        android:layout_below="@+id/firsttext"
        android:background="@drawable/border"
        android:ellipsize="marquee"
        android:lines="4"
        android:scrollbars="vertical"
        android:textAppearance="?android:attr/textAppearanceMedium" />

That also doesn't work

thankyou
  • 211
  • 1
  • 5
  • 13
  • to get input you need edittext box. and if you want then vertically then set orientation of linear layout as vertical and if horizontal then orientation as horizontal – BSKANIA Feb 05 '14 at 10:51

4 Answers4

6

Too many dependencies, check if you are getting any circular dependency error in xml. As per your requirement, without specifying the spacing and other UI details, a solution:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@android:color/black" >

    <TextView
        android:id="@+id/firsttext"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@android:color/white"
        android:text="first"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/secondtext"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/firsttext"
        android:background="@android:color/white"
        android:text="second"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/thirdtext"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/secondtext"
        android:background="@android:color/white"
        android:text="third"
        android:textAppearance="?android:attr/textAppearanceMedium" />

</RelativeLayout>
Pararth
  • 8,114
  • 4
  • 34
  • 51
0

Try

android:layout_width="match_parent"
android:layout_centerInParent="true"
android:layout_toLeftOf="@id/thirdText"
android:layout_toRightOf="@id/firstText"

Make sure to add your left and right TextView first with the fixed width and

android:layout_alignParentLeft="true"

and

android:layout_alignParentRight="true" 
ElDuderino
  • 3,253
  • 2
  • 21
  • 38
0

Your question is not clear. But try this.. If you are using Relative layout as parent then

<TextView
android:id="@+id/secondtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@id/firsttext"
android:background="@drawable/border"
android:scrollbars="vertical"
android:textAppearance="?android:attr/textAppearanceMedium" />

to show three textviews in horizontal way.

<TextView
android:id="@+id/secondtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/firsttext"
android:background="@drawable/border"
android:scrollbars="vertical"
android:textAppearance="?android:attr/textAppearanceMedium" />

to show in vertical way..

saa
  • 1,538
  • 2
  • 17
  • 35
  • But if my second text is too long, the thirdtext is no longer on display.. because the second Text is not defined.. – thankyou Feb 05 '14 at 11:58
  • no vertical but the second Text (the text in the middle) is not defined and if it's too long the third text will be out of screen – thankyou Feb 05 '14 at 12:07
  • 1
    This is common problem. To avoid this, set following attribute to some value android:layout_width="100dp" //value is your wish. – saa Feb 05 '14 at 12:10
0

Define a LinearLayout with height="wrap_content" and width="fill_parent".

You can overcome your problem with two ways. Either add android:layout_below="@id/TextViewExample" in your Textviews or use android:layout_marginTop="10dip"

  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/black" >

        <TextView
            android:id="@+id/firsttext"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@android:color/white"
            android:text="first"
             android:layout_marginTop="10dip"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <TextView
            android:id="@+id/secondtext"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/firsttext"
            android:background="@android:color/white"
            android:text="second"
            android:layout_below="@id/firstText"
             android:layout_marginTop="20dip"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <TextView
            android:id="@+id/thirdtext"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/secondtext"
            android:background="@android:color/white"
            android:text="third"
             android:layout_marginTop="30dip"
            android:textAppearance="?android:attr/textAppearanceMedium" 
            android:layout_below="@id/secondtext"/>

    </LinearLayout>
Ivan Chernykh
  • 41,617
  • 13
  • 134
  • 146