Android ImageButton масштабируется и поддерживает соотношение сторон

У меня есть экран, который я пытаюсь разметить...

По сути, я пытаюсь равномерно распределить 4 объекта ImageButton по вертикали на экране... Я использовал это здесь, чтобы равномерно распределить элементы, но теперь мне ужасно трудно заставить изображения масштабироваться, но сохранять пропорции... если я использую scaleType="centerInside", они не масштаб, если я использую «fitXY», они не сохраняют пропорции... вот как выглядит макет:

введите здесь описание изображения

и вот код:

    <LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent" android:layout_margin="0dp"
  android:padding="0dp"
  android:orientation="vertical"
  android:weightSum="5"
  >


        <ImageButton android:id="@+id/share_song" 
            android:layout_width="fill_parent" android:text=""
            android:layout_marginLeft="0dp"
            android:layout_marginTop="15dp"
            android:layout_marginRight="5dp"
            android:layout_marginBottom="5dp"
            android:gravity="left" 
            android:src="@drawable/share_song_button_sel"
            android:adjustViewBounds="true"
            android:background="#0000"
            android:scaleType="fitXY"
          android:layout_height="0dp"
          android:layout_weight="1"
            />
        <Button 
            android:layout_width="wrap_content" 
            android:text="" android:id="@+id/tag_a_song"
            android:layout_marginLeft="5dp"
            android:layout_marginTop="10dp"
            android:layout_marginRight="0dp"
            android:layout_marginBottom="5dp"
            android:gravity="right" 
            android:layout_gravity="right"
            android:background="@drawable/song_check_in_button_sel"
          android:layout_height="0dp"
          android:layout_weight="1"
            />
        <Button android:id="@+id/match_button" 
            android:layout_width="wrap_content" android:text=""
            android:layout_marginLeft="0dp"
            android:layout_marginTop="10dp"
            android:layout_marginRight="0dp"
            android:layout_marginBottom="5dp"
            android:gravity="left" 
            android:background="@drawable/music_match_button_sel"
          android:layout_height="0dp"
          android:layout_weight="1"
            />
        <Button android:id="@+id/friends_button" 
            android:layout_width="wrap_content" android:text=""
            android:layout_marginLeft="0dp"
            android:layout_marginTop="10dp"
            android:layout_marginRight="0dp"
            android:layout_marginBottom="5dp"
            android:gravity="right" 
            android:layout_gravity="right"
            android:background="@drawable/my_friends_music_button_sel"
          android:layout_height="0dp"
          android:layout_weight="1"
            />

        <LinearLayout
          xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="fill_parent"
          android:layout_height="0dp"
          android:layout_weight="1"
          android:orientation="horizontal"
          android:layout_marginRight="0dp"
          android:layout_marginLeft="0dp"
          android:layout_marginTop="0dp"
          android:padding="0dp" 
          >
        <LinearLayout
          xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="fill_parent"
          android:layout_height="65dp"
          android:orientation="horizontal"
          android:layout_marginRight="0dp"
          android:layout_marginLeft="0dp"
          android:layout_marginTop="0dp"
          android:padding="0dp" 
          android:layout_gravity="bottom"
          >
        <ImageView android:src="@drawable/trending_bar"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_gravity="top"
          android:layout_marginRight="0dp"
          android:layout_marginLeft="0dp"
          android:layout_marginTop="10dp"
          android:scaleType="fitXY"/>

            </LinearLayout>
        </LinearLayout> 

</LinearLayout>

Надеюсь, кто-то может помочь.


person john ellis    schedule 13.05.2011    source источник


Ответы (1)


Установите ширину ImageButtons на fill_parent и используйте масштаб fitStart для изображений, которые охватывают левое поле, и fitEnd для тех, что справа. Должен сработать, по крайней мере, в том, что касается вашего примера изображения. У вас могут возникнуть некоторые проблемы с интервалами, если пропорциональная ширина изображений превышает ширину экрана, но это должно сработать для вас.

person Kevin Coppock    schedule 13.05.2011
comment
большое спасибо за быстрый ответ... я попробовал это, и это не увеличивает изображение... также, если экран слишком мал, он не уменьшит его. - person john ellis; 13.05.2011
comment
хотя я только проверял это в редакторе wysiwyg ... может быть, мне не следует этому доверять. - person john ellis; 13.05.2011
comment
Да, не верьте, по моему опыту, с такими вещами ужасно. Попробуйте на эмуляторе или на устройстве. - person Kevin Coppock; 13.05.2011
comment
о да... это безумие... эмулятор показывает все это хорошо... большое спасибо за помощь! - person john ellis; 13.05.2011
comment
Верно ли это на сегодняшний день? - person nembleton; 12.07.2012