2015-07-12 57 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