2013-02-08 9 views
5

Mam LinearLayout w orientacji poziomej i 2 ImageView i chcę, aby ImagesView wypełnić 50% szerokości ekranu, do pracy w każdym telefonie komórkowym lub tablecie o różnych rozmiarach.Jak umieścić 50% szerokości?

coś takiego:

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

Najlepszy do tej pory:

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

Każdy ImageView powinien mieć 'android: layout_width = "0DP"' i 'androdi: layout_weight = "1"' –

+0

Użyj Androida: layout_weight = "". – user1744952

+0

Thx @SherifelKhatib Rozwiąż mój problem = DD. –

Odpowiedz

9

Napisz następujący kod, aby to zrobić w obu widokach wewnątrz LinearLayout.

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

Dzięki Chintan to było bardzo pomocne = D. –

+0

@Guilherme to moja przyjemność ... :-) –

1

Dodaj android:layout_weight="1" zarówno w ImageView i to szerokość, jeśli widok obraz jako fill_parent myślę, że będzie rozwiązać problem

Pamiętaj jednak, że rozciągnie to zdjęcie, ponieważ widok obrazu będzie się rozciągał w każdej rozdzielczości ekranu, tak aby Twój obraz.

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

Użyj android: weightSum i 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> 
Powiązane problemy