2017-07-11 3 views
0

フル画面に合わせて:はGridLayoutには、私は私のレイアウトはこのようにしたい

Layout Diagram

を今私はのGridLayoutで働いており、これが私の現在のXML

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:background="#000000" 
> 


<GridLayout 
android:id="@+id/GridLayout1" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:columnCount="2" 
android:fillViewport="true" 
> 

<!-- Button 1 --> 
    <Button 
    android:id="@+id/B1" 
    android:layout_column="0" 
    android:layout_columnSpan="2" 
    android:layout_row="0" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="Button 1" 
    android:textColor="@android:color/white" 
    android:background="@drawable/schalt2" 
    /> 

<!-- Button 2 --> 

<Button 
    android:id="@+id/B2" 
    android:layout_row="1" 
    android:layout_column="0" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Button 2" 
    android:textColor="@android:color/white" 
    android:background="@drawable/schalt2" 
    /> 

<Button 
    android:id="@+id/B3" 
    android:layout_row="2" 
    android:layout_column="0" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Button 3" 
    android:textColor="@android:color/white" 
    android:background="@drawable/schalt2" 
    /> 

<Button 
    android:id="@+id/B4" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_column="1" 
    android:layout_row="1" 
    android:layout_columnSpan="1" 
    android:layout_rowSpan="2" 

    android:layout_gravity="fill_vertical" 
    android:background="@drawable/schalt2" 
    android:text="Button 4" 
    android:textColor="@android:color/white" /> 

<!-- Button 5--> 

<Button 
    android:id="@+id/B5" 
    android:layout_column="0" 
    android:layout_columnSpan="2" 
    android:layout_row="3" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="Button 5" 
    android:textColor="@android:color/white" 
    android:background="@drawable/schalt2" /> 

<!-- Button 6 --> 
<Button 
    android:id="@+id/B6" 
    android:layout_column="0" 
    android:layout_columnSpan="2" 
    android:layout_row="4" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/VIP" 
    android:text="Button 6" 
    android:textColor="@android:color/white" 
    android:background="@drawable/schalt2" 
    /> 

</GridLayout> 
</LinearLayout> 

は、まあ、空がたくさんあるさあなたが見ることができるように左のスペース: Design

私の両親の高さに一致するようにGridLayoutを取得するにはどうすればよいですか?

タブレイアウトでも試してみましたが、ボタン2とボタン3がボタン4で2行に収まるようになると、TayLayoutが限界に達しました。 ここで何ができますか?

+0

からGoogleFlexboxLayout

dependencies { compile 'com.google.android:flexbox:0.3.0' }

XMLを追加します。 –

+0

私の単純なケースでは少し難しいようです。これらのボタンと特定のデザインでアクティビティを開始するには、OnClickListenerが必要です。 –

答えて

0

Google flexbox-layoutを使用してください。ここでは、リンクの: - :これはあなたがhttps://inducesmile.com/android/android-staggeredgridlayoutmanager-example-tutorial/探しているものである

<?xml version="1.0" encoding="utf-8"?> 
<com.google.android.flexbox.FlexboxLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="#000000" 
android:orientation="vertical" 
android:weightSum="4" 
app:alignContent="stretch" 
app:alignItems="stretch" 
app:flexWrap="wrap"> 

<Button 
    android:id="@+id/B1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@android:color/holo_blue_bright" 
    android:text="Button 1" 
    android:textColor="@android:color/white" /> 

<com.google.android.flexbox.FlexboxLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    app:flexDirection="column" 
    app:layout_flexBasisPercent="50%"> 

    <Button 
     android:id="@+id/B2" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:background="@android:color/holo_green_dark" 
     android:text="Button 2" 
     android:textColor="@android:color/white" 
     /> 

    <Button 
     android:id="@+id/B3" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:background="@android:color/holo_green_light" 
     android:text="Button 3" 
     android:textColor="@android:color/white" 
     /> 

</com.google.android.flexbox.FlexboxLayout> 


<Button 
    android:id="@+id/B4" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@android:color/holo_orange_light" 
    android:text="Button 4" 
    android:textColor="@android:color/white" 
    app:layout_flexBasisPercent="50%" /> 


<Button 
    android:id="@+id/B5" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@android:color/holo_purple" 
    android:text="Button 5" 
    android:textColor="@android:color/white" /> 


<Button 
    android:id="@+id/B6" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@android:color/holo_blue_dark" 
    android:text="Button 6" 
    android:textColor="@android:color/white" /> 

</com.google.android.flexbox.FlexboxLayout> 
+0

こんにちは。私はこのトピックに別の質問を持っています - 経験豊かなユーザーが私を助けてくれるかもしれません。 https://stackoverflow.com/questions/45175407/flexboxlayout-with-buttons-with-background-images-how-to-maintain-their-size –

関連する問題