2013-02-08 10 views
5

私は、水平方向と2つのImageViewでLinearLayoutを持っています。そして、幅が画面の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のは 'アンドロイドを持っている必要がありlayout_weight = "1"' –

+0

をandroid:layout_weight = ""を使用してください。 – user1744952

+0

Thx @SherifelKhatib私の問題を解決する= DD。 –

答えて

9

LinearLayoutの両方のビューでこれを行うには、次のコードを記述します。

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

非常に有益だったチャタン=ありがとうD。 –

+0

@Guilhermeその私の喜び... :-) –

1

は両方ImageViewandroid:layout_weight="1"を追加し、画像表示が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

利用アンドロイド:weightSumとAndroid:layout_width = "0dp" `と` androdi: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> 
関連する問題