2013-02-11 4 views
2

В основном у меня есть ImageView в одном из линейных макетов, когда весы установлены на каждом из моих макетов, которые изменяются, то же самое происходит с ImageView в макете. Проблема - только высота, которая фактически меняет ширину, остается неизменной.layout_weight изменяет размеры изображения

Почему это проблема? У меня есть customView, и мне нужно поместить его на чашку, чтобы он требовал x, y пучков чашки и размера (ширины и высоты). Теперь я получаю разную ширину с разными размерами экрана.

Код Компоновка:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:layout_weight="3" 
     android:orientation="horizontal" > 

     <RelativeLayout 
      android:id="@+id/rlmainContainer" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" > 

      <ImageView 
       android:id="@+id/ivCup" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/cup1_r" /> 
     </RelativeLayout> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" > 
    </LinearLayout> 

</LinearLayout> 

решение Archie.bpgc (установка layout_height = "0dp") не помогает. Установка несколько изображений, и все они с непропорциональной шириной:

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

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:orientation="horizontal" > 



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

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" > 

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

    </LinearLayout> 

     <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" > 

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

    </LinearLayout> 

     <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" > 

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

    </LinearLayout>  

</LinearLayout> 

ответ

1

Сделать свой layout_height = 0dp при установке веса. Это тоже оптимизация.

android:layout_height="0dp" 

для обоих LinearLayouts.

А также вам не нужны RelativeLayout, поскольку у вас есть только один ImageView в 1-й LinearLayout

+0

Не помогает, спасибо за быстрый ответ. – user2060190

+0

@ user2060190 выглядит как я неправильно понял вопрос. Вы хотите, чтобы ваши «ImageViews» были равны по высоте ** (что я мог сделать из вашего кода). Если вы хотите, чтобы ширина была одинаковой для всех изображений, удалите 'wrap_content' и установите некоторое значение или' fill_parent'. –

Смежные вопросы