为什么要使用Android AppCompat v7 GridLayout?
问题描述:
是否有理由使用Android AppCompat v7 GridLayout而不是旧的GridLayout? v7 GridLayout是否具有旧版本没有的功能?使用v7 GridLayout还有其他好处吗?为什么要使用Android AppCompat v7 GridLayout?
使用v7 GridLayout有缺点吗?当应用程序使用v7 GridLayout时,应用程序必须在其依赖项中包含另一个库。附加依赖性是否有缺点?
答
当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
您可以在代码中使用。
请查看https://developer.android.com/topic/libraries/support-library/index.html –
谢谢。该链接的信息很有帮助。然而,这是相当一般的信息,并没有回答我关于GridLayout的问题。 – Barzee