首页 > 解决方案 > 图像未填满正方形

问题描述

我希望图像填满所有框,我不想在它们之间有那些边框。图像没有填满所有的方框。我尝试了一切,但没有任何效果。如果有人可以帮助我,我将非常感激,问题是当我将它旋转 90 度时。

Photo1 这就是它的 样子 Photo2 这就是我想要的样子

 <LinearLayout
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:layout_weight="1">

    <RelativeLayout
     android:layout_width="match_parent"
     android:layout_height="match_parent">

       <ImageView
        android:id="@+id/tile2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"/>

       <ImageView
        android:id="@+id/tile_player_2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1" />

       <ImageView
        android:id="@+id/tile_enemy_2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1" />
     </RelativeLayout>
  </LinearLayout>

这是java

    tiles[2].setImageResource(getResources().getIdentifier("tile_lava", "drawable", getPackageName()));
    tiles[0].setRotation(90);

当我旋转它时,我会在它们之间收到空格

标签: javaandroidxmllayout

解决方案


尝试将以下内容添加到layout.xml中不适合磁贴的 Imageviews。

android:scaleType="fitXY"

编辑

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:weightSum="3">

        <ImageView
            android:id="@+id/tile2"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:scaleType="fitXY"
            android:layout_weight="1" />

        <ImageView
            android:id="@+id/tile_player_2"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:scaleType="fitXY"
            android:layout_weight="1" />

        <ImageView
            android:id="@+id/tile_enemy_2"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:scaleType="fitXY"
            android:layout_weight="1" />
</LinearLayout>

推荐阅读