Android Gridview元素对齐
我现在设计的截图 但我希望设计与下面的设计类似 网格布局如下所示Android Gridview元素对齐,android,gridview,android-imageview,textview,Android,Gridview,Android Imageview,Textview,我现在设计的截图 但我希望设计与下面的设计类似 网格布局如下所示 <?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"
<?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>
<?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>
单个gridview元素布局如下所示
<?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>
<?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>
试试这个
<?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>
效果很好,但一些长文本实际上隐藏在图像后面。我将添加新的图像。给我一秒钟。我在最后的问题中添加了新的图像,看一看。没有,仍然是相同的输出。文本隐藏在下一行图像的后面。你能尝试删除图像和文本之间的边距吗?哦,然后尝试android:singleLine=“true”它将以单线滚动。实际上,我想到了这一点,但没有告诉kiran ask Kirant这是有效的,但我想显示整个内容。它显示为延续(大学注册…)。如果不是一行两行的话,我想展示整个过程。但是第一个问题呢?将图像扩展到整个屏幕,如我所放置的图像。