0

Мне нужно создать несколько изображений, чтобы заполнить несколько элементов ImageButton, которые я определил в XML, и кнопки автоматически изменяются в соответствии с размером экрана.Каков рекомендуемый подход к созданию изображений для ImageButton с динамическим размером?

Например, я использую Photoshop для создания одного из этих изображений. Как узнать, какой размер для установки изображения, разрешения, соотношения сторон и т. Д.? Очевидно, что не рекомендуется растягивать изображения или что-то в этом роде, поэтому я немного потерян.

Я не знаю, имеет ли это значение в этом случае, но я оставлю здесь свой код вместе с скриншотом того, как он выглядит.

XML:

<?xml version="1.0" encoding="utf-8"?> 

<GridLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/content_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:columnCount="2" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:context="pt.ismai.a26800.readr.MainActivity" 
    tools:showIn="@layout/activity_main"> 

    <ImageButton 
     android:id="@+id/imageButton1" 
     android:layout_columnWeight="1" 
     android:layout_rowWeight="1" 
     app:srcCompat="@mipmap/ic_launcher" 
     tools:ignore="ContentDescription" /> 

    <ImageButton 
     android:id="@+id/imageButton2" 
     android:layout_columnWeight="1" 
     android:layout_rowWeight="1" 
     app:srcCompat="@mipmap/ic_launcher" 
     tools:ignore="ContentDescription" /> 

    <ImageButton 
     android:id="@+id/imageButton3" 
     android:layout_columnWeight="1" 
     android:layout_rowWeight="1" 
     app:srcCompat="@mipmap/ic_launcher" 
     tools:ignore="ContentDescription" /> 

    <ImageButton 
     android:id="@+id/imageButton4" 
     android:layout_columnWeight="1" 
     android:layout_rowWeight="1" 
     app:srcCompat="@mipmap/ic_launcher" 
     tools:ignore="ContentDescription" /> 

    <ImageButton 
     android:id="@+id/imageButton5" 
     android:layout_columnWeight="1" 
     android:layout_rowWeight="1" 
     app:srcCompat="@mipmap/ic_launcher" 
     tools:ignore="ContentDescription" /> 

    <ImageButton 
     android:id="@+id/imageButton6" 
     android:layout_columnWeight="1" 
     android:layout_rowWeight="1" 
     app:srcCompat="@mipmap/ic_launcher" 
     tools:ignore="ContentDescription" /> 

    <ImageButton 
     android:id="@+id/imageButton7" 
     android:layout_columnWeight="1" 
     android:layout_rowWeight="1" 
     app:srcCompat="@mipmap/ic_launcher" 
     tools:ignore="ContentDescription" /> 

    <ImageButton 
     android:id="@+id/imageButton8" 
     android:layout_columnWeight="1" 
     android:layout_rowWeight="1" 
     app:srcCompat="@mipmap/ic_launcher" 
     tools:ignore="ContentDescription" /> 

</GridLayout> 

Layout:

enter image description here

ответ

0

заказ https://github.com/bumptech/glide Вы можете установить DiskCacheStrategy на то, что поведение, которое вы хотите. Это означает, что он может загружать изображение в размер изображения или полноразмерного изображения в память.

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