0

我需要创建一些图像来填充我在XML中定义的一些ImageButton元素,并且按钮会根据屏幕大小自动调整大小。为动态大小的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> 

布局

enter image description here

回答

相关问题