2017-06-19 168 views
-1

我使用的是android studio 2.3.2,而我的問題是,當我向應用程序添加gridlayout時,我無法更改列和行的數量,還有一條消息說這個網格佈局沒用也我無法添加任何圖像到圖像視圖的gridlayout.I已經嘗試添加使用屬性設計視圖中的行和列,也使用xml文本視圖,但它不工作,我也看不到任何網格線,當我拖動imagelay over gridlayout時。網格佈局不能正常工作

+0

一個小的預覽,請看看這個:https://stackoverflow.com/help/how-to-ask – Henry

回答

0

使用支持庫中的android.support.v7.widget.GridLayout來管理android中的網格佈局。

下面

<android.support.v7.widget.GridLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:fitsSystemWindows="true" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
xmlns:tools="http://schemas.android.com/tools" 
tools:background="@drawable/bg_paper" 
app:rowCount="4" 
app:columnCount="3" 
app:orientation="vertical" 
android:layout_marginBottom="50dp"> 

<android.support.v7.widget.AppCompatImageView 
    android:layout_width="0dp" 
    android:layout_height="0dp" 
    app:layout_columnSpan="2" 
    app:layout_row="0" 
    app:layout_column="0" 
    app:layout_rowWeight="5" 
    app:layout_columnWeight="1" 
    app:layout_gravity="fill" 
    android:scaleType="fitCenter" 
    app:srcCompat="@drawable/img_onboarding_search" /> 
<TextView 
    app:layout_row="1" 
    app:layout_column="0" 
    app:layout_rowWeight="1" 
    app:layout_columnWeight="1" 
    app:layout_gravity="fill" 
    android:text="@string/onboarding_title_step_1"/> 

<TextView 
    app:layout_row="2" 
    app:layout_column="0" 
    app:layout_rowWeight="5" 
    app:layout_columnWeight="1" 
    app:layout_gravity="fill" 
    android:text="@string/onboarding_message_step_1"/></android.support.v7.widget.GridLayout>