0

У меня есть макет для ввода страны в базу данных в моем приложении. Я хотел бы, чтобы мой макет был прокручиваемым, потому что на некоторых устройствах клавиатура может блокировать текстовые поля. Я знаю, что я могу использовать ScrollView для этого, но у меня проблема. Мой макет состоит из полного LinearLayout, но я включил 2 кнопки внутри этого в RelativeLayout. Это дает мне необычный метод прокрутки, где весь экран, кажется, прокручивается, даже когда я не вхожу в текст, оставляя большой зазор в нижней части экрана. Любые мысли по этому поводу?Относительная компоновка в линейном макете возможна с прокруткой?

Вот мой макет:

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    > 
    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical" 
     android:background="@drawable/map" 
     android:scrollbars = "vertical" > 

     <!-- Enter country --> 
     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:hint="@string/editcountry" 
      android:textColor="@color/black" 
      android:textSize="22sp" /> 

     <AutoCompleteTextView 
      android:id="@+id/editcountry" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:hint="@string/hintprompt" 
      android:imeOptions="actionDone" /> 

     <!-- Enter year --> 
     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:hint="@string/edityear" 
      android:textColor="@color/black" 
      android:textSize="22sp" /> 

     <Spinner 
      android:id="@+id/yearspin" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"/> 

     <!-- Enter month --> 
     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:hint="@string/editmonth" 
      android:textColor="@color/black" 
      android:textSize="22sp" /> 

     <Spinner 
      android:id="@+id/monthspin" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:entries="@array/months" /> 

     <!-- Enter mode of transport --> 
     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:hint="@string/edittransport" 
      android:textColor="@color/black" 
      android:textSize="22sp" /> 

     <Spinner 
      android:id="@+id/transportspin" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:entries="@array/transport" /> 

     <!-- Enter description --> 
     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:hint="@string/editdesc" 
      android:textColor="@color/black" 
      android:textSize="22sp" /> 

     <EditText 
      android:id="@+id/editdesc" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:hint="@string/hintprompt" 
      android:inputType="text" 
      android:imeOptions="actionDone"/> 

      <!-- Place buttons at the bottom of the screen --> 
      <RelativeLayout 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:orientation="vertical" > 

       <Button 
        android:id="@+id/backmain" 
        android:layout_width="150dp" 
        android:layout_height="50dp" 
        android:layout_alignParentBottom="true" 
        android:layout_alignParentLeft="true" 
        android:text="@string/back" /> 

       <Button 
        android:id="@+id/add" 
        android:layout_width="150dp" 
        android:layout_height="50dp" 
        android:layout_alignParentBottom="true" 
        android:layout_alignParentRight="true" 
        android:text="@string/addinfo" /> 

      </RelativeLayout> 
    </LinearLayout> 
</ScrollView> 

ответ

0

Ваш LinearLayout имеет его высота устанавливается в fill_parent. Измените это на wrap_content. Аналогичным образом устанавливается ваш RelativeLayout. Также может быть виновником.

<LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:background="@drawable/map" 
     android:scrollbars = "vertical" > 
0

Вы также можете поместить свой scrollView в другой макет. Есть один вертикальный LinearLayout с двумя макетах внутри, один для вашего все, что нужно прокручивать с layout_weight = «1» и в нижней части другой макет, который состоит из ваших кнопок

Ваш макет будет что-то похожее на это:

Vertical LinearLayout 
    LinearLayout with layout_weight="1" 
     ScrollView 
      Layout containing your stuff 
    layout containing buttons 
Смежные вопросы