2013-02-08 8 views
5

Ich habe eine LinearLayout in horizontaler Ausrichtung und 2 ImageView und ich möchte, dass ImagesView 50% der Bildschirmbreite ausfüllen, um in jedem Handy oder Tablet mit verschiedenen Größen zu arbeiten.Wie 50% für Breite setzen

Etwas wie folgt aus:

+-------------+ 
|_____________|  
|  |  | 
| 50% | 50% | 
|  |  | 
|-------------| 
|    | 
+-------------+ 

Beste bis jetzt:

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


     <ImageView 
      android:id="@+id/logo_c" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/logo_animado" /> 

     <ImageView 
      android:id="@+id/logo_t" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:src="@drawable/logo_animado2" /> 


</LinearLayout> 
+2

Jedes Image sollte 'android haben: layout_width = "0DP"' und 'androdi: layout_weight = "1"' –

+0

Verwenden Sie android: layout_weight = "". – user1744952

+0

Thx @SherifelKhatib Löse mein Problem = DD. –

Antwort

9

Schreiben Sie den folgenden Code, um dies in beiden Ansichten innerhalb LinearLayout zu tun.

android:layout_width="0dp" 
layout_weight="1" 
+1

Danke Chintan, das war sehr hilfreich = D. –

+0

@Guilherme es ist mir ein Vergnügen ... :-) –

1

hinzufügen android:layout_weight="1" sowohl in der ImageView und die Breite machen, wenn die Bildansicht als fill_parent ich denke, es Ihr Problem lösen

Aber denken Sie daran, es wird Ihr Bild als Bild strecken, da Bildansicht in jeder Bildschirmauflösung streachen wird dein Bild.

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


    <ImageView 
     android:id="@+id/logo_c" 
     android:layout_width="0dp" 
     android:layout_weight="50" 
     android:layout_height="wrap_content" 
     android:src="@drawable/logo_animado" /> 

    <ImageView 
     android:id="@+id/logo_t" 
     android:layout_height="wrap_content" 
     android:layout_width="0dp"  
     android:layout_weight="50" 
     android:src="@drawable/logo_animado2" /> 


</LinearLayout> 
2

Verwenden android: weightSum und android: layout_weight

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


      <ImageView 
       android:id="@+id/logo_c" 
       android:layout_width="0dp" android:layout_weight="1" 
       android:layout_height="wrap_content" 
       android:src="@drawable/logo_animado" /> 

      <ImageView 
       android:id="@+id/logo_t" 
       android:layout_width="0dp" android:layout_weight="1" 
       android:layout_height="wrap_content" 
       android:src="@drawable/logo_animado2" /> 


    </LinearLayout> 
Verwandte Themen