2013-02-08 55 views
5

我有一個水平方向的LinearLayout和2個ImageView,我想讓這個ImagesView在寬度上填充50%的屏幕,以在不同尺寸的每個手機或平板電腦上工作。如何把50%的寬度

事情是這樣的:

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

迄今爲止最好的:

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

每個ImageView的應該有'的android:layout_width = 「0dp」'和'androdi:layout_weight = 「1」' – 2013-02-08 12:58:10

+0

使用android:layout_weight =「」。 – user1744952 2013-02-08 12:59:21

+0

Thx @SherifelKhatib解決我的問題= DD。 – 2013-02-08 13:09:30

回答

9

請在LinearLayout以內的兩個視圖中輸入以下代碼。

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

感謝Chintan,這非常有幫助= D。 – 2013-02-08 13:12:33

+0

@Guilherme我的榮幸...... :-) – 2013-02-08 13:14:49

1

添加android:layout_weight="1"同時在ImageView,使寬度如果圖像視圖爲fill_parent我認爲這將解決您的問題

但請記住它會拉伸您的圖像,因爲圖像視圖將在每個屏幕分辨率中都會流傳你的形象。

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

使用Android:weightSum和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> 
相關問題