Android Layout lower and higher

I got three TextViews. The first and third are determined with a change in text. Secondly, the TextView between the first and the third gets the value through input. How to set second textview between first and third in 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" />

This does not 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" />

This also does not work.

+4
source share
4 answers

Too many dependencies, check if you get any circular dependency error in xml. According to your requirement without specifying the distance and other details of the user interface, the 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>
0
source

Try

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

Be sure to add the left and right TextView first with a fixed width and

android:layout_alignParentLeft="true"

and

android:layout_alignParentRight="true" 
0

Your question is not clear. But try this .. If you are using Relative layout as a 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 display three text images in a 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" />

for vertical display.

0
source

Define LinearLayoutwith height="wrap_content"and width="fill_parent".

You can solve your problem in two ways. Either add android:layout_below="@id/TextViewExample"to the text fields or useandroid: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>
0
source

Source: https://habr.com/ru/post/1525393/


All Articles