2013-02-08 27 views
5

मेरे पास क्षैतिज अभिविन्यास और 2 छवि दृश्य में एक रैखिक लयआउट है और मैं छवियों को चौड़ाई पर 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_width =" 0dp "' और 'androdi: layout_weight =" 1 "' –

+0

एंड्रॉइड का प्रयोग करें: layout_weight = ""। – user1744952

+0

Thx @ शेरिफेलखतिब मेरी समस्या हल करें = डीडी। –

उत्तर

9

LinearLayout के अंदर दोनों विचारों में ऐसा करने के लिए निम्न कोड लिखें।

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

धन्यवाद चिंतन जो बहुत उपयोगी था = डी। –

+0

@ गुइलेरमेम मेरी खुशी ... :-) –

1

दोनों ImageView में android: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 और एंड्रॉयड: 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>