2011-06-01 5 views
0

J'essaie de créer une mise en page simple, mais je ne trouve pas de moyen de le faire. La disposition devrait avoir 3 éléments: TextView en haut, EditText (avec scrollview) au milieu et bouton en bas. J'ai fait ce code:Problème de mise en page Android

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:weightSum="1" 
    android:orientation="vertical" 
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent"> 

    <LinearLayout android:layout_weight="0.97" 
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent" 
    android:id="@+id/linearLayout18" 
    android:orientation="vertical"> 
    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"   
     android:text="Text:" 
     android:gravity="center_vertical"/> 

    <ScrollView android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <EditText 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:id="@+id/txtMessage" 
     android:text=""/> 

    </ScrollView> 
    </LinearLayout> 
    <LinearLayout 
    android:layout_weight="0.03" 
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent" 
    android:id="@+id/linearLayout1" 
    android:orientation="vertical"> 
     <Button 
     android:text="Next" 
     android:id="@+id/button1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     />  
    </LinearLayout> 
</LinearLayout> 

Mais il me donne la mise en page comme ceci: Layout Comme vous pouvez voir le problème est que EditText ne prendra pas tout l'espace vertical disponible (tout le chemin à bouton). Comment résoudre ceci?

Répondre

1

Il suffit d'utiliser android:fillViewport="true" dans votre ScrollView

+0

Deux réponses identiques (et correctes). J'ai choisi le vôtre - vous avez répondu en premier :) Solution simple et efficace, merci! :) – guest86

+0

n'étant pas gourmand mais je mérite un upvote aussi! :) – doNotCheckMyBlog

1

essayer relativelayout au lieu de linéaire ici est le code SAMLE

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent"> 

    <RelativeLayout android:layout_height="wrap_content" 
    android:layout_width="fill_parent" 
    android:id="@+id/linearLayout18" android:layout_alignParentTop="true"> 
    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"   
     android:text="Text:" 
     android:id="@+id/textMessage" 
     android:gravity="center_vertical" android:layout_alignParentTop="true"/> 

    <ScrollView android:layout_width="fill_parent" 
    android:layout_below="@+id/textMessage" android:layout_above="@+id/button1" android:scrollbars="horizontal|vertical" android:layout_height="fill_parent" android:fillViewport="true"> 

    <EditText 
     android:id="@+id/txtMessage" 
     android:text="" android:layout_height="fill_parent" android:layout_width="fill_parent"/> 

    </ScrollView> 


     <Button 
     android:text="Next" 
     android:id="@+id/button1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true"/>  
    </RelativeLayout> 
</RelativeLayout> 
+0

Eh bien, en ajoutant juste android: fillViewport = "vrai" problème résolu, pourquoi devrais-je utiliser "mise en page relative"? – guest86

0

Essayez cette .... C'est parfait ... Je suis dans mon testé studio android ..... C'est la même disposition que vous voulez ....

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent"> 

    <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="Text:" 
      android:id="@+id/textview1" 
      android:layout_alignParentTop="true"/> 


     <ScrollView android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:fillViewport="true" 
      android:layout_above="@id/btn" 
      android:layout_below="@id/textview1"> 

      <EditText 
       android:layout_width="fill_parent" 
       android:layout_height="match_parent" 
       android:id="@+id/txtMessage" 
       android:text=""/> 

     </ScrollView> 

    <Button 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/txtMessage" 
     android:id="@+id/btn" 
     android:text="Next" 
     android:layout_alignParentBottom="true"/> 

    </RelativeLayout>