2014-02-05 6 views
4

У меня есть три TextViews. Первая и третья определяются с изменением текста. Во-вторых, TextView между первым и третьим получает значение с помощью ввода. Как установить второй TextView между первым и третьим в макете?Android 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" /> 

Это не работает!

<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" /> 

Это также не работает

+0

, чтобы получить вход вам нужно EditText окно. и если вы хотите, то по вертикали, тогда установите ориентацию линейного макета как вертикальную, а если горизонталь, то ориентация как горизонтальная – BSKANIA

ответ

0

Слишком много зависимостей, проверьте, если вы получаете любую ошибку круговой зависимостей в XML. В соответствии с вашим требованием, без указания расстояния и других деталей пользовательского интерфейса, решения:

<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

Но если мой второй текст слишком длинный, третий текст больше не отображается. Потому что второй текст не определен. – thankyou

+0

, если вы имеете в виду, что второй текст является многострочным и отталкивает третий текст, укажите эллипсис и одну строку или строки в текстовом виде или только во втором тексте. – user2450263

+0

не может четко понять ваше требование, можете ли вы опубликовать, что теперь выводится для вашего кода выше и что/как вы хотите, чтобы оно было – user2450263

0

Попробуйте

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

Убедитесь, чтобы добавить свой левый и правый TextView первый с фиксированной шириной и

android:layout_alignParentLeft="true" 

и

android:layout_alignParentRight="true" 
0

Ваш вопрос непонятен. Но попробуйте это .. Если вы используете относительный компоновщик в качестве родителя, то

<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" /> 

показать три TextViews в горизонтальном пути.

<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" /> 

показать в вертикальном пути ..

+0

Но если мой второй текст слишком длинный, третий текст больше не отображается. потому что второй текст не определен. – thankyou

+0

Вы показываете их горизонтально? – saa

+0

нет вертикальной, но второй текст (текст в середине) не определен, и если он слишком длинный, третий текст будет вне экрана – thankyou

0

Определение LinearLayout с height="wrap_content" и width="fill_parent".

Вы можете преодолеть свою проблему двумя способами. Либо добавить android:layout_below="@id/TextViewExample" в вашем TextViews или использовать 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> 
Смежные вопросы