2017-06-08 13 views
0

私はゲームTic-Tac-Toeのフィールドを持っています。各セルはImageButtonです。クリックすると、画像が挿入されます。ImageButtonの空き領域

Before

After

fragment_game.xml

<TableLayout 
     android:id="@+id/tableGame" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_margin="50dp" 
     android:background="@android:color/black"> 

     <TableRow 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1"> 

      <ImageButton 
       android:id="@+id/button1" 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_margin="2dp" 
       android:layout_weight="1" 
       android:background="@android:color/white" /> 

      <ImageButton 
       android:id="@+id/button3" 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_margin="2dp" 
       android:layout_weight="1" 
       android:background="@android:color/white" /> 

      <ImageButton 
       android:id="@+id/button2" 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_margin="2dp" 
       android:layout_weight="1" 
       android:background="@android:color/white" /> 
     </TableRow> 

     <TableRow 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1"> 

      <ImageButton 
       android:id="@+id/button9" 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_margin="2dp" 
       android:layout_weight="1" 
       android:background="@android:color/white" /> 

      <ImageButton 
       android:id="@+id/button5" 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_margin="2dp" 
       android:layout_weight="1" 
       android:background="@android:color/white" /> 

      <ImageButton 
       android:id="@+id/button4" 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_margin="2dp" 
       android:layout_weight="1" 
       android:background="@android:color/white" /> 
     </TableRow> 

     <TableRow 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1"> 

      <ImageButton 
       android:id="@+id/button8" 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_margin="2dp" 
       android:layout_weight="1" 
       android:background="@android:color/white" /> 

      <ImageButton 
       android:id="@+id/button7" 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_margin="2dp" 
       android:layout_weight="1" 
       android:background="@android:color/white" /> 

      <ImageButton 
       android:id="@+id/button6" 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_margin="2dp" 
       android:layout_weight="1" 
       android:background="@android:color/white" /> 
     </TableRow> 

    </TableLayout> 

そしてFragment_game.java

final ImageButton btn = (ImageButton) V.findViewById(R.id.button5); 
btn.setScaleType(ImageButton.ScaleType.FIT_CENTER); 
btn.setAdjustViewBounds(true); 
btn.setOnClickListener(new View.OnClickListener() { 
    @Override 
    public void onClick(View v) { 
     btn.setImageResource(R.drawable.qwe); 
    } 
}); 
:しかし、上部と下部にいくつかの空のスペースがあります

画像をセルのサイズに伸ばしたいです。あなたはマージン、パディングを使用

答えて

0
android:layout_margin="2dp" 

その後、あなたがEaislyお仕事anotherwise CONTはそれが助けをdoesnの `t

+0

番を行うことができますマージンとパディングを削除してください。 – Farad

+0

@ファラッド私はあなたに言いたいYOUあなたはレイアウトマージンを削除し、セットは0dpです –

関連する問題