2015-03-01 2 views
1

Я полный новичок в программировании для Android, и я работаю с TextViews. Я хочу два TextViews с одним сверху и одним снизу. Но это не работает, и я не знаю, почему. Вот XMLTextview не пропущен до следующей строки android

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" 
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"> 
<TextView 
    android:text="@string/hello_world" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" /> 

<TextView 
    android:text="@string/hello_world" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 
</LinearLayout> 

Так что я первый TextView как fill_parent для ширины, чтобы пропустить строку, но вместо этого он просто принимает его. Я не могу добавить изображение, поскольку я только что сделал эту учетную запись для этого вопроса, но он просто отображает первый TextView, а не следующий. Какую ошибку я сделал?

ответ

1

В LinearLayout вам необходимо установить ориентацию.

android:orientation="vertical" 
+0

где это идти? – voodoocode

+0

Он идет под LinearLayout. Вот документация со всеми атрибутами в LinearLayout: http://developer.android.com/reference/android/widget/LinearLayout.html – IntegralOfTan

1

Используйте этот код, здесь ориентация отсутствует в коде

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" 
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:orientation="vertical" 
tools:context=".MainActivity"> 
<TextView 
    android:text="@string/hello_world" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" /> 

<TextView 
    android:text="@string/hello_world" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 
</LinearLayout> 
Смежные вопросы