0

J'ai une mise en page pour entrer un pays dans une base de données dans mon application. Je voudrais que ma mise en page soit défilante car sur certains appareils, le clavier peut bloquer les champs de texte. Je sais que je peux utiliser ScrollView pour le faire mais j'ai un problème. Ma mise en page consiste en un LinearLayout global mais j'ai inclus 2 boutons dans celui-ci dans un RelativeLayout. Cela me donne une méthode de défilement inhabituelle où tout l'écran semble défiler même si je n'entre pas dans le texte, laissant un grand vide en bas de l'écran. Des pensées à ce sujet?La disposition relative dans la disposition linéaire est scrollview possible?

Voici ma mise en page:

<?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> 

Répondre

0

Votre LinearLayout a sa hauteur réglée sur fill_parent. Changez pour wrap_content. Votre RelativeLayout est défini de la même manière. Pourrait aussi être le coupable.

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

Vous pouvez également placer votre scrollView dans une autre disposition. Avoir un LinearLayout vertical avec deux mises en page à l'intérieur, un pour votre tout ce qui doit faire défiler avec layout_weight = « 1 » et au fond une autre disposition qui se composent de vos boutons

Votre mise en page sera quelque chose de similaire à ceci:

Vertical LinearLayout 
    LinearLayout with layout_weight="1" 
     ScrollView 
      Layout containing your stuff 
    layout containing buttons 
Questions connexes