2017-10-17 88 views
1

是否有理由使用Android AppCompat v7 GridLayout而不是舊的GridLayout? v7 GridLayout是否具有舊版本沒有的功能?使用v7 GridLayout還有其他好處嗎?爲什麼要使用Android AppCompat v7 GridLayout?

使用v7 GridLayout有缺點嗎?當應用程序使用v7 GridLayout時,應用程序必須在其依賴項中包含另一個庫。附加依賴性是否有缺點?

+1

請查看https://developer.android.com/topic/libraries/support-library/index.html –

+0

謝謝。該鏈接的信息很有幫助。然而,這是相當一般的信息,並沒有回答我關於GridLayout的問題。 – Barzee

回答

2

當android api < 21,它不工作。

因此,更多地使用它來適應Android版本。

所以我們可以添加編譯。

compile 'com.android.support:gridlayout-v7:25.3.1' 

和樣本。

<android.support.v7.widget.GridLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/GridLayout1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#f11" 
    app:columnCount="2" 
    app:rowCount="2"> 

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

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

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

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

</android.support.v7.widget.GridLayout> 

注意

com.android.support:gridlayout-v7:25.3.1

25.3.1改變你自己。

它有新的屬性。

  • 應用:layout_columnWeight
  • 應用:layout_rowWeight
  • 應用:layout_rowSpan
  • 應用:layout_columnSpan

您可以在代碼中使用。

相關問題