2011-10-24 6 views
0

J'ai un linearLayout qui est entouré par un scrollView afin de le rendre plus petit pour les écrans scrollable. Dans la disposition linéaire j'ai 3 enfants qui sont également linearlayout.Linearlayout pour différentes tailles d'écran

Cela fonctionne très bien. Mais je veux aussi supporter de plus grands écrans. Au moment où je reçois avec un plus grand espace d'écran à gauche sur le bas de l'écran. Je veux que les boutons (barre de navigation) soient toujours en bas. pour les plus grands écrans (hauteur) je voudrais ajouter en haut de l'écran une vue vide qui remplit l'espace qui est plus fourni par le grand écran.

Comment puis-je y parvenir? J'ai essayé beaucoup avec l'attribut de poids mais n'ai pas fonctionné.

Voici la mise en page:

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:background="#8db9f6" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <LinearLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:background="#8db9f6"> 
     <LinearLayout 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:orientation="horizontal" 
      android:layout_marginTop="8dp" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"> 
      <TextView 
       android:text="test" 
       android:id="@+id/test" 
       android:paddingLeft="10dp" 
       android:textStyle="bold" 
       android:textSize="20dp" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content"> 
      </TextView> 
      <View 
       android:layout_width="wrap_content" 
       android:layout_height="0dip" 
       android:layout_weight="1"/> 
      <ImageButton 
       android:id="@+id/btnName" 
       android:scaleType="center" 
       android:layout_width="60dp" 
       android:layout_height="48dp" 
       android:src="@android:drawable/ic_menu_edit"> 
      </ImageButton> 
     </LinearLayout> 
     <EditText 
      android:id="@+id/edittest" 
      android:editable="false" 
      android:hint="@string/test" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"> 
     </EditText> 
     <TextView 
      android:text="@string/optionalText" 
      android:id="@+id/test1" 
      android:paddingLeft="10dp" 
      android:textSize="12dp" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"> 
     </TextView> 
     <TextView 
      android:id="@+id/space" 
      android:layout_width="fill_parent" 
      android:layout_marginTop="4dp" 
      android:layout_height="3sp" 
      android:background="#333142"> 
     </TextView> 
     <LinearLayout 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:orientation="horizontal" 
      android:layout_marginTop="5dp" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"> 
      <TextView 
       android:text="TEST TESt" 
       android:id="@+id/test2" 
       android:paddingLeft="10dp" 
       android:layout_marginTop="5dp" 
       android:textStyle="bold" 
       android:textSize="20dp" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content"> 
      </TextView> 
      <View 
       android:layout_width="wrap_content" 
       android:layout_height="0dip" 
       android:layout_weight="1"/> 
      <ProgressBar 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:visibility="gone" 
       android:id="@+id/progressbar"/> 
      <ImageButton 
       android:id="@+id/btnPicture" 
       android:scaleType="center" 
       android:layout_width="60dp" 
       android:layout_height="48dp" 
       android:src="@android:drawable/ic_menu_edit"> 
      </ImageButton> 
     </LinearLayout> 
     <FrameLayout 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:orientation="horizontal" 
      android:background="#ffffff" 
      android:layout_gravity="center" 
      android:layout_width="fill_parent" 
      android:layout_height="150dip"> 
      <ImageView 
       android:id="@+id/test3" 
       android:layout_width="400dip" 
       android:layout_height="150dip" 
       android:layout_gravity="center" 
       android:scaleType="fitCenter" 
       android:src="@drawable/test1"/> 
      <TextView 
       android:id="@+id/text" 
       android:layout_gravity="bottom" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textSize="8dp" 
       android:text="test test"/> 
     </FrameLayout> 
     <LinearLayout 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:orientation="horizontal" 
      android:layout_gravity="bottom" 
      android:layout_marginTop="3dp" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"> 
      <Button 
       android:id="@+id/scaleMinus" 
       android:textSize="14dp" 
       android:layout_weight="1" 
       android:layout_gravity="bottom" 
       android:layout_width="fill_parent" 
       android:layout_height="40dp" 
       android:text="@string/zoomOut"/> 
      <Button 
       android:id="@+id/scalePlus" 
       android:textSize="14dp" 
       android:layout_weight="1" 
       android:layout_gravity="bottom" 
       android:layout_width="fill_parent" 
       android:layout_height="40dp" 
       android:text="@string/zoomIn"/> 
     </LinearLayout> 
     <TextView 
      android:id="@+id/balken" 
      android:layout_width="fill_parent" 
      android:layout_marginTop="4dp" 
      android:layout_height="3sp" 
      android:background="#333142"> 
     </TextView> 
     <LinearLayout 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:orientation="horizontal" 
      android:layout_marginTop="5dp" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"> 
      <TextView 
       android:text="test test" 
       android:id="@+id/test3" 
       android:paddingLeft="10dp" 
       android:textStyle="bold" 
       android:textSize="20dp" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content"> 
      </TextView> 
      <View 
       android:layout_width="wrap_content" 
       android:layout_height="0dip" 
       android:layout_weight="1"/> 
      <EditText 
       android:id="@+id/test4" 
       android:editable="false" 
       android:layout_width="100dp" 
       android:layout_height="wrap_content"> 
      </EditText> 
      <TextView 
       android:text="test" 
       android:id="@+id/mtest4" 
       android:paddingLeft="10dp" 
       android:textStyle="bold" 
       android:textSize="20dp" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content"> 
      </TextView> 
      <View 
       android:layout_width="wrap_content" 
       android:layout_height="0dip" 
       android:layout_weight="1"/> 
      <ImageButton 
       android:id="@+id/test5" 
       android:scaleType="center" 
       android:layout_width="60dp" 
       android:layout_height="48dp" 
       android:src="@android:drawable/ic_menu_edit"> 
      </ImageButton> 
     </LinearLayout> 
     <TextView 
      android:id="@+id/balken" 
      android:layout_width="fill_parent" 
      android:layout_marginTop="4dp" 
      android:layout_height="3sp" 
      android:background="#333142"> 
     </TextView> 
     <LinearLayout 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:orientation="horizontal" 
      android:layout_gravity="bottom" 
      android:background="#000000" 
      android:paddingTop="5dp" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"> 
      <Button 
       android:id="@+id/save" 
       android:textSize="18dp" 
       android:layout_weight="1" 
       android:layout_gravity="bottom" 
       android:layout_width="fill_parent" 
       android:layout_height="60dp" 
       android:text="@string/save"/> 
      <Button 
       android:id="@+id/cancel" 
       android:textSize="18dp" 
       android:layout_weight="1" 
       android:layout_gravity="bottom" 
       android:layout_width="fill_parent" 
       android:layout_height="60dp" 
       android:text="@string/abort"/> 
     </LinearLayout> 
    </LinearLayout> 
</ScrollView> 
+0

Avez-vous essayé d'utiliser fill_parent dans les mises en page? Pouvez-vous poster le fichier layout.xml pour voir à quoi il ressemble afin que nous puissions mieux vous aider? –

+0

oui j'ai défini fill_parent. Je vais poster la mise en page. – tobias

Répondre

2

Utilisez une disposition relative en tant qu'élément racine et définissez la disposition linéaire contenant vos boutons sur layout_alignParentBottom = "true" et le paramètre ScrollView sur layout_alignParentTop = "true". Le LinearLayout contenant les boutons et le ScrollView doivent être des enfants directs de RelativeLayout.

<RelativeLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
     <LinearLayout <-- containing the layout minus the buttons 
       android:id="@+id/SV" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignParentTop="true"> 
      <The Rest Of The Layout> 
     </LinearLayout> 
     <LinearLayout 
       android:id="@+id/LLButtons" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignParentBottom="true"> 
      <Buttons> 
      </LinearLayout> 
</ScrollView> 

Si vous voulez que les boutons soient toujours en bas de l'écran alignParentBottom. Si vous voulez que les boutons soient toujours en bas du scrollview alignBelow = "@ id/SV"

+0

Thx. Mais le démarrage de ScrollView? – tobias

+0

ok merci, c'est sympa. Mais maintenant, l'espace est au-dessus des boutons. Je le veux en haut de l'écran. – tobias

+0

Vous voulez que la mise en page soit ancrée en bas de l'écran et que tout espace vide soit en haut? Aucun problème. Buttons = alignParentBottom = true & le LL avec le reste de la disposition sera alignAbove = "@ id/LLButtons" – Phobos

0

android:layout_height="wrap_content" dans votre LinearLayout intérieur est votre problème ici, changer à 'fill_parent' devrait aider. En général, vous pouvez utiliser hierarchyviewer pour résoudre les problèmes de mise en page comme celui-ci. Enveloppez la mise en page entière dans une mise en page relative.

+0

J'ai 3 versions linéaires internes. devrais-je utiliser pour chacun d'eux fill_parent pour la taille? – tobias

Questions connexes