2015-07-12 56 views
1

我現在的設計GridView的元素排列

enter image description here

的截圖,但我想要的設計是這樣的設計之下

enter image description here

網格佈局是如下

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".MainActivity" > 

    <GridView 
     android:id="@+id/grid" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:columnWidth="100dip" 
     android:gravity="center" 
     android:numColumns="2" 
     android:stretchMode="spacingWidthUniform" /> 

</LinearLayout> 

單gridview的元件佈局是如下

<?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="vertical" > 

    <ImageView 
     android:id="@+id/grid_image" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:contentDescription="@string/im" > 
    </ImageView> 

    <TextView 
     android:id="@+id/grid_text" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:maxLength="23" 
     android:gravity="center" 
     android:layout_marginTop="10sp" 
     android:textSize="12sp" > 
    </TextView> 

</LinearLayout> 

enter image description here

回答

1
嘗試

<?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="vertical" > 

    <ImageView 
     android:id="@+id/grid_image" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:scaleType="fitXY" 
     android:contentDescription="@string/im" > 
    </ImageView> 

    <TextView 
     android:id="@+id/grid_text" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:maxLength="23" 
     android:gravity="center" 
     android:layout_marginTop="10sp" 
     android:paddingTop="10dp" 
     android:paddingBottom="10dp" 
     android:textSize="12sp" > 
    </TextView> 

</LinearLayout> 
+0

它會在單行滾動 – NilayDani

+0

然後你想要什麼? –

+0

其實我想到了這一點,但沒有告訴基蘭 問基蘭 – NilayDani

0
 <?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="vertical" > 

<ImageView 
    android:id="@+id/grid_image" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    > 
</ImageView> 

<TextView 
    android:id="@+id/grid_text" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:maxLength="23" 
    android:padding="10dp" 
    android:layout_weight="1" 
    android:textSize="12sp" > 
</TextView> 

Try this in your row layout 
+0

工作正常,但一些長文本實際上隱藏在圖像後面。我會添加新的圖像。你稍等一會兒。 –

+0

我已經在最後的問題上添加了新圖片,請看一看。 –

+0

編輯答案嘗試一下 – NilayDani