Подтвердить что ты не робот

Android: Как заполнить RelativeLayout до полной ширины экрана?

Я создаю приложение Android, в котором есть основной RelativeLayout и некоторые LinearLayout внутри него.

Теперь у меня есть эта проблема. При перетаскивании элементов в редактор, например. LinearLayout, он не подходит для полной ширины экрана. Как я могу сделать это возможным? Это мой XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:gravity="fill"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<LinearLayout
    android:id="@+id/itemDetailLayout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:orientation="vertical" 
    android:fillViewport="true" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
        android:orientation="horizontal" >

        <ImageView
            android:id="@+id/itemImage"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:minHeight="40dp"
            android:minWidth="40dp"
            android:src="@drawable/ic_launcher" />

        <TextView
            android:id="@+id/itemName"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:text="Name"
            android:textAppearance="?android:attr/textAppearanceMedium" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:orientation="vertical" 
        android:fillViewport="true" >

        <TextView
            android:id="@+id/itemRecentHigh"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Recent High" />

        <TextView
            android:id="@+id/itemRecentLow"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Recent Low" />

        <TextView
            android:id="@+id/itemAverage"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Average" />
    </LinearLayout>
</LinearLayout>

<LinearLayout
    android:id="@+id/listViewLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/itemDetailLayout"
    android:layout_marginTop="10dp"
    android:fillViewport="true"
    android:gravity="fill_horizontal"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/searchListView"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:fillViewport="true" >

    </ListView>
</LinearLayout>

Добавлен снимок экрана для получения дополнительной информации. Добавлен синий фон, чтобы иметь некоторый контраст.

http://i.stack.imgur.com/tPxsE.png

4b9b3361

Ответ 1

Замените это:

   android:layout_width="wrap_content"
   android:layout_height="wrap_content"

С

   android:layout_width="match_parent"
   android:layout_height="wrap_content"

в ваш LinearLayout или удалить все дополнения из основного RelativeLayout

Ответ 2

Удаление прокладки делает линейную компоновку подходящей для всего экрана устройства

Ответ 3

Пространство между синей частью и "концом экрана". По бокам и над частью, где находятся кнопка "Назад" и кнопка "Дом".

Удалите прокладку из корня RelativeLayout.

Ответ 4

Try

<LinearLayout
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:orientation="vertical>
   // Other views within the linear layout
</LinearLayout>

Я предполагаю, что вы используете Eclipse. Лично я ненавижу графический редактор Eclipse, и я обычно пишу XML-код напрямую, потому что работа с редактором - настоящая боль.

Ответ 5

вы должны попробовать что-то вроде следующего:

<LinearLayout
    android:id="@+id/itemDetailLayout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" 
     >

...


</LinearLayout>

что я имею в виду, вы должны это сделать:

android:layout_width="fill_parent"

для каждого LinearLayout, чтобы ваша ширина была заполнена.

FILL_PARENT означает, что представление хочет быть таким же большим, как и его родительский элемент, как указано в документации.

и, пожалуйста, дайте мне несколько отзывов

Надеюсь, что это поможет.

Ответ 6

Не используйте fill_parent, поскольку он устарел. Вместо этого установите RelativeLayout

android:layout_width="fill_parent"
android:layout_height="fill_parent"

Затем в виде списка, который вы хотите заполнить на остальной части экрана, вы можете установить эти теги

android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"

Таким образом, вы сообщаете XML, что вы хотите, чтобы ваш ListView выполнял то, что раньше делал fill_parent в предыдущих версиях Android.

С уважением!