【问题标题】:Image doesn't fill the square图像未填满正方形
【发布时间】:2020-01-14 08:03:20
【问题描述】:

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

照片1 this is how it is 照片2 this is how i want

 <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);

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

【问题讨论】:

    标签: java android xml layout


    【解决方案1】:

    尝试在 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>
    

    【讨论】:

      【解决方案2】:

      RelativeLayout 是不必要的,它会破坏您的设计。去掉它。 如果您的图片不是 1x1 比例,请添加 android:scaleType="fitXY" 以避免出现白色空白。

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

      【讨论】:

      • 嗨,没有相对布局它会给我一个错误,因为我使用重量
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-19
      • 1970-01-01
      • 2015-05-19
      • 2016-12-22
      • 1970-01-01
      • 2013-08-18
      相关资源
      最近更新 更多