2017-02-24 2 views
0

私は現在、これを持っている:GridLayoutのボタンサイズを「match_parent」に変更するにはどうすればよいですか?

enter image description here

そして、私が取得しようとしているこの:

私は今、1時間以上試してみましたが、それは働いてもらうように見えることはできません

enter image description here

。以下の私のXMLを見てください。私は「match_parent」のように、彼は全体で行われる最後のボタンを変更するにはどうすればよい

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
android:background="@drawable/png1" 
    android:layout_height="match_parent"> 

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

     <Button 
      android:text="Button" 
      android:layout_width="100dp" 
      android:layout_height="100dp" 
      android:layout_columnWeight="1" 
      android:layout_rowWeight="1" 
      android:id="@+id/button1" /> 

     <Button 
      android:text="Button" 
      android:layout_width="100dp" 
      android:layout_height="100dp" 
      android:layout_columnWeight="1" 
      android:layout_rowWeight="1" 
      android:id="@+id/button2" /> 

     <Button 
      android:text="Button" 
      android:layout_width="100dp" 
      android:layout_height="100dp" 
      android:layout_columnWeight="1" 
      android:layout_rowWeight="1" 
      android:id="@+id/button3" 
      android:layout_row="1" 
      android:layout_column="1" /> 
     <Button 
      android:text="Button" 
      android:layout_width="100dp" 
      android:layout_height="100dp" 
      android:layout_columnWeight="1" 
      android:layout_rowWeight="1" 
      android:id="@+id/button4" 
      android:layout_row="1" 
      android:layout_column="0" /> 
     <Button 
      android:text="Button" 
      android:layout_width="100dp" 
      android:layout_height="100dp" 
      android:layout_columnWeight="1" 
      android:layout_rowWeight="1" 
      android:id="@+id/button5" 
      android:layout_row="2" 
      android:layout_column="0" /> 


    </GridLayout> 
</LinearLayout> 

? おかげ

答えて

0

android:layout_width="100dp"のを使用してみてください。これにより、ボタンが2列にまたがるようになります。

<Button 
     android:text="Button" 
     android:layout_columnSpan="2" 
     android:layout_width="100dp" 
     android:layout_height="100dp" 
     android:layout_columnWeight="1" 
     android:layout_rowWeight="1" 
     android:id="@+id/button5" 
     android:layout_row="2" 
     android:layout_column="0" /> 
+0

から回答を受け入れました。アンドロイド:layout_width = "100dp"をandroid:layout_width = "match_parent"に設定しようとしましたが、これが起こります:https://i.gyazo.com/11594914718f3351ac8d35b58ab5c138.png –

+0

私の編集した投稿をチェックしてください。それはあなたが望む結果を与えるはずです。 –

0

android:id="@+id/button5"android:layout_columnSpan="2"を追加し、この

android:layout_width="match_parent" 

代わり

+0

私はすでにアンドロイドを設定しようとしました:アンドロイドへ=「100dp」layout_width:layout_width =「match_parent」が、その後、この問題が発生した:https://i.gyazo.com/11594914718f3351ac8d35b58ab5c138.png –

+0

あなたは正しい答えを持っていますまだですか? –

+0

はい@Drew –

関連する問題