2016-07-19 11 views
0

Ich habe eine Aktivität:die Schaltfläche in einem Gridlayout Maximieren

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.GridLayout 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" 
            app:rowCount="4" 
            app:columncount="4"> 

<Button 
    android:text="1" 
    android:id="@+id/button1" 
    app:layout_gravity="fill" 
    app:layout_rowWeight="1" 
    app:layout_columnWeight="1" 
    app:layout_row="0" 
    app:layout_column="0""/> 


<Button 
    android:text="2" 
    android:id="@+id/button2" 
    app:layout_rowWeight="1" 
    app:layout_columnWeight="1" 
    app:layout_gravity="fill" 
    app:layout_row="0" 
    app:layout_column="1"/> 

<Button 
    android:text="3" 
    android:id="@+id/button3" 
    app:layout_rowWeight="1" 
    app:layout_columnWeight="1" 
    app:layout_gravity="fill" 
    app:layout_row="0" 
    app:layout_column="2"/> 

<Button 
    android:text="4" 
    android:id="@+id/button5" 

    app:layout_gravity="fill" 
    app:layout_row="1" 
    app:layout_column="0"/> 

<Button 
    android:text="5" 
    android:id="@+id/button6" 
    app:layout_rowWeight="1" 
    app:layout_columnWeight="1" 
    app:layout_gravity="fill" 
    app:layout_row="1" 
    app:layout_column="1"/> 

<Button 
    android:text="6" 
    android:id="@+id/button7" 
    app:layout_rowWeight="1" 
    app:layout_columnWeight="1" 
    app:layout_gravity="fill" 
    app:layout_row="1" 
    app:layout_column="2"/> 
<Button 
    android:text="7" 
    android:id="@+id/button8" 
    app:layout_rowWeight="1" 
    app:layout_columnWeight="1" 
    app:layout_gravity="fill" 
    app:layout_row="2" 
    app:layout_column="0"/> 
<Button 
    android:text="8" 
    android:id="@+id/button9" 
    app:layout_rowWeight="1" 
    app:layout_columnWeight="1" 
    app:layout_gravity="fill" 
    app:layout_row="2" 
    app:layout_column="1"/> 

<Button 
    android:text="9" 
    android:id="@+id/button4" 
    app:layout_gravity="fill" 
    app:layout_rowWeight="1" 
    app:layout_columnWeight="1" 
    app:layout_row="2" 
    app:layout_column="2" 
    /> 

, die wie folgt aussieht:

Current layout

möchte ich ändern Sie die Taste 1, so dass es würde vertikal geschichtet und 4 und 7 müssen minimiert werden, um wrap_contnet (hergestellt in Photoshop) enter image description here

Was ist der beste Weg, dies zu tun?

Genauer gesagt, muss ich dies machen:

enter image description here

Ich habe dies durch benutzerdefinierte Breite, aber ich weiß nicht, wie dies mit Layouts zu machen:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.GridLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
xmlns:grid="http://schemas.android.com/apk/res-auto" 
tools:context="com.example.win72.myapplication.MainActivity" 
grid:columnCount="3" 
grid:rowCount="3"> 


<TextView 
    grid:layout_gravity="fill" 
    grid:layout_columnWeight="1" 
    grid:layout_rowWeight="10" 
    grid:layout_row="0" 
    grid:layout_column="0" 
    grid:layout_rowSpan="2" 

    android:textSize="60sp" 
    android:background="#a49595" 
    android:text="90" 
    android:id="@+id/textView" 
    android:clickable="true" 
    android:layout_height="457dp"/> 

<TextView 
    grid:layout_gravity="fill" 
    grid:layout_columnWeight="1" 
    grid:layout_rowWeight="10" 
    grid:layout_row="0" 
    grid:layout_column="2" 
    grid:layout_rowSpan="2" 

    android:textSize="60sp" 
    android:background="#a49595" 
    android:text="90" 
    android:id="@+id/textView2"/> 

<TextView 
    grid:layout_row="2" 
    grid:layout_column="0" 
    grid:layout_gravity="fill_horizontal" 
    grid:layout_columnWeight="1" 

    android:gravity="center" 
    android:textSize="30sp" 
    android:text="4" 
    android:id="@+id/textView3"/> 

<TextView 
    grid:layout_row="2" 
    grid:layout_column="2" 
    grid:layout_gravity="fill_horizontal" 


    android:text="6" 
    android:id="@+id/textView4" 
    android:gravity="center" 
    android:textSize="30sp" 
    /> 

<Button 
    grid:layout_row="0" 
    grid:layout_column="1" 
    grid:layout_columnWeight="1" 
    grid:layout_gravity="fill_horizontal" 
    android:text="Reset" 
    android:id="@+id/button"/> 

<Button 
    grid:layout_row="1" 
    grid:layout_column="1" 
    grid:columnweight="1" 
    grid:layout_gravity="fill_horizontal" 

    android:text="Next" 
    android:id="@+id/button2" 
    /> 

+0

hast du hier geschaut? https://github.com/etsy/AndroidStaggeredGrid –

+0

Verwenden Sie dies kann helfen, http://android-pratap.blogspot.in/2015/01/using-linearlayoutmanager.html –

Antwort

0

Mit staggeredgridlayout können Sie das erreichen.

+0

Ist es der einzige Weg? Ich kann es nicht schaffen, indem ich die Gewichte verändere oder so etwas? – proggamer12

+0

GridView-Elemente (Schaltflächen) Anzahl ist konstant? oder dynamisch ändern? –

+0

Wenn es nur mit dynamic funktioniert, dann werde ich das Layout in dynamic ändern. – proggamer12

0

fand ich, dass dynamische Anzahl der Zeilen/Spalten Herstellung und Verwendung rowspan dies machen kann:

Dank let Hilfe

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.GridLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
xmlns:grid="http://schemas.android.com/apk/res-auto" 
tools:context="com.example.win72.myapplication.MainActivity"> 


<TextView 
    grid:layout_gravity="fill" 
    grid:layout_columnWeight="1" 
    grid:layout_rowWeight="1" 
    grid:layout_row="0" 
    grid:layout_column="0" 
    grid:layout_rowSpan="3" 

    android:textSize="60sp" 
    android:background="#a49595" 
    android:text="90" 
    android:id="@+id/textView" 
    android:clickable="true" 
    /> 

<TextView 
    grid:layout_gravity="fill" 
    grid:layout_columnWeight="1" 
    grid:layout_rowWeight="1" 
    grid:layout_row="0" 
    grid:layout_column="2" 
    grid:layout_rowSpan="3" 

    android:textSize="60sp" 
    android:background="#a49595" 
    android:text="90" 
    android:id="@+id/textView2"/> 

<TextView 
    grid:layout_row="3" 
    grid:layout_column="0" 
    grid:layout_gravity="fill_horizontal" 
    grid:layout_columnWeight="1" 

    android:gravity="center" 
    android:textSize="30sp" 
    android:text="4" 
    android:id="@+id/textView3"/> 

<TextView 
    grid:layout_row="3" 
    grid:layout_column="2" 
    grid:layout_gravity="fill_horizontal" 


    android:text="6" 
    android:id="@+id/textView4" 
    android:gravity="center" 
    android:textSize="30sp" 
    /> 

<Button 
    grid:layout_row="0" 
    grid:layout_column="1" 
    grid:layout_columnWeight="1" 
    grid:layout_gravity="fill_horizontal" 
    android:text="Reset" 
    android:id="@+id/button"/> 

<Button 
    grid:layout_row="1" 
    grid:layout_column="1" 
    grid:layout_columnWeight="1" 
    grid:layout_gravity="fill_horizontal" 

    android:text="Next" 
    android:id="@+id/button2" 
    /> 

enter image description here

!