попробуйте отобразить семь кнопок с прокруткой на маленьком экране

Я пытаюсь поместить в свой макет семь кнопок на маленьком экране, чтобы протестировать его (Galaxy young), поэтому я использовал прокрутку, но у меня все еще есть проблемы ( >экран не прокручивается в режиме LandScape).

это мой xml-код:

 <?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:fillViewport="true">

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:orientation="horizontal" >

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
         android:layout_height="?android:attr/listPreferredItemHeight"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:gravity="center_horizontal"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/lieu_depart"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Lieu de prise en charge"
            style="" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:layout_alignParentLeft="false"
        android:layout_alignParentRight="false"
        android:layout_below="@+id/linearLayout1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="@dimen/activity_vertical_margin" >

        <Button
            android:id="@+id/button2_date_depart"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="50dp"
            android:text="Date1" />

        <Button
            android:id="@+id/time_depart5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="70dp"
            android:text="Time1" />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout3"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_below="@+id/linearLayout2"
        android:layout_centerHorizontal="true"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/button4"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:minWidth="@dimen/activity_vertical_margin"
            android:text="Lieu de restitution" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout4"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/linearLayout3"
        android:layout_marginTop="@dimen/activity_vertical_margin"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/button5_date_arrive"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="50dp"
            android:text="Date2" />

        <Button
            android:id="@+id/button6_time_arrive"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="70dp"
            android:text="Time2" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/linearLayout4"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/Button03"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="Button" />

    </LinearLayout>

</RelativeLayout>
</ScrollView>

РЕДАКТИРОВАНИЕ: Портретный режим:

введите здесь описание изображения

Пейзажный режим:

введите здесь описание изображения

что я должен использовать, чтобы ограничить эту проблему?

Спасибо


person Inès Belhouchet    schedule 11.08.2013    source источник


Ответы (3)


РЕДАКТИРОВАТЬ..

Чтобы исправить это, вам нужно добавить к своим кнопкам следующее: «android:layout_below="@id/id вашей кнопки", см. ниже.

<Button
    android:id="@+id/lieu_depart"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Lieu de prise en charge"
    style="" />

<Button
    android:id="@+id/button2_date_depart"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="50dp"
    android:layout_below="@id/lieu_depart"
    android:text="Date1" />

<Button
    android:id="@+id/time_depart5"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="70dp"
    android:layout_below="@id/button2_date_depart"
    android:text="Time1" />

<Button
    android:id="@+id/button4"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minWidth="@dimen/activity_vertical_margin"
    android:layout_below="@id/time_depart5"
    android:text="Lieu de restitution" />

<Button
    android:id="@+id/button5_date_arrive"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/button4"
    android:layout_marginLeft="50dp"
    android:text="Date2" />

<Button
    android:id="@+id/button6_time_arrive"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/button5_date_arrive"
    android:layout_marginLeft="70dp"
    android:text="Time2" />

<Button
    android:id="@+id/Button03"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/button6_time_arrive"
    android:gravity="center"
    android:text="Button" />

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

person user2675503    schedule 12.08.2013
comment
Привет, я пробую ваш код, но он не работает. Последняя кнопка не появляется, когда я поворачиваю телефон (режим альбомной ориентации). просто хочу сказать, что тестирую его с галакси юнг (маленький экран)!! Я уверен, что такие устройства хорошо поддерживают ландшафтный режим, но я все еще ищу, как адаптировать его к моим приложениям !! извините за мой английский - person Inès Belhouchet; 12.08.2013

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

<RelativeLayout 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"
tools:context=".MainActivity" >

<ScrollView                         
    android:layout_width="fill_parent"         
    android:layout_height="fill_parent">              
<RelativeLayout 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">


   <Button
        android:id="@+id/lieu_depart"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Lieu de prise en charge"
        style="" />

    <Button
        android:id="@+id/button2_date_depart"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="50dp"
        android:text="Date1" />

    <Button
        android:id="@+id/time_depart5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="70dp"
        android:text="Time1" />

    <Button
        android:id="@+id/button4"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minWidth="@dimen/activity_vertical_margin"
        android:text="Lieu de restitution" />

    <Button
        android:id="@+id/button5_date_arrive"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="50dp"
        android:text="Date2" />

    <Button
        android:id="@+id/button6_time_arrive"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="70dp"
        android:text="Time2" />

    <Button
        android:id="@+id/Button03"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="Button" />

       </RelativeLayout>                    
     </ScrollView>


 </RelativeLayout>

РЕДАКТИРОВАТЬ...

Вам нужно добавить «android:layout_below="@+id/идентификатор вашей кнопки" на каждую кнопку, чтобы кнопки отображались друг под другом.

 <Button
        android:id="@+id/lieu_depart"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Lieu de prise en charge"
        style="" />

    <Button
        android:id="@+id/button2_date_depart"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/lieu_depart"
        android:layout_marginLeft="50dp"
        android:text="Date1" />

    <Button
        android:id="@+id/time_depart5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/button2_date_depart"
        android:layout_marginLeft="70dp"
        android:text="Time1" />

    <Button
        android:id="@+id/button4"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/time_depart5"
        android:minWidth="@dimen/activity_vertical_margin"
        android:text="Lieu de restitution" />

    <Button
        android:id="@+id/button5_date_arrive"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/button4"
        android:layout_marginLeft="50dp"
        android:text="Date2" />

    <Button
        android:id="@+id/button6_time_arrive"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="70dp"
        android:layout_below="@+id/button5_date_arrive"
        android:text="Time2" />

    <Button
        android:id="@+id/Button03"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/button6_time_arrive"
        android:gravity="center"
        android:text="Button" />

Затем вы можете поиграть с расположением кнопок, установив гравитацию и поля. Теперь это должно решить вашу проблему.

person Allrounder    schedule 11.08.2013

Вы должны использовать LienarLayout внутри ScrollView. RelativeLayout игнорирует ориентацию и используется, когда вы хотите разместить элементы с абсолютной позицией. В макете xml есть много вещей, которые нужно изменить. Можете ли вы отправить изображение вашего макета, чтобы понять, что именно вы хотите.

Здесь у вас есть :

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Starting place" />
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center">
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Date 1" />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Time 1" />
    </LinearLayout>
    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Arrival place" />
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center">
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Date2" />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="50dp"
            android:text="Time2" />
    </LinearLayout>
    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Submit" />
</LinearLayout>
</ScrollView>

В последнем linearlayout 2-я кнопка я включил layout_marginLeft, но с центром тяжести linearlayout он будет центрировать кнопки и делить это пространство между двумя кнопками, поэтому вы можете манипулировать пространством между ними.

По умолчанию макет заполняет родительский элемент, но на втором изображении у вас есть что-то вроде правого поля, если вам это нужно, вы можете использовать android квалификаторы конфигурации, но лучший способ не дублировать xml макета – использовать квалификатор values-land и добавить папку dimens, где вы можете добавить значение заполнения и добавить в свой макет первый дочерний элемент макета scrollview android:paddingRight="@dimen/your_property_name". Подробнее об ресурсах измерения.

person Kirill Ryabin    schedule 12.08.2013
comment
Хорошо, я добавил изображение для двух режимов (пейзаж и портрет). Вы можете увидеть это сейчас. - person Inès Belhouchet; 12.08.2013