I have the following layout :
<?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"
android:background="#ededed" >
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="#172982"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:textStyle="bold"
android:textColor="#ffffff"
android:textSize="20sp"
android:text="Stories" />
<GridView
android:id="@+id/grid"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clipChildren="true"
android:columnWidth="150dp"
android:gravity="center"
android:numColumns="auto_fit"
android:scrollbars="none"
android:stretchMode="columnWidth" >
</GridView>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingBottom="5dp"
android:paddingLeft="9dp"
android:paddingRight="9dp"
android:paddingTop="5dp" >
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="#172982"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:textStyle="bold"
android:textColor="#ffffff"
android:textSize="20sp"
android:text="Dictionaries" />
</LinearLayout>
</LinearLayout>
In this layout I'm filling each cell of the gridview with a linearlayout containing an imageview and a textview through the following xml file :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/grid_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true">
</ImageView>
<TextView
android:id="@+id/grid_text"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginTop="5dp"
android:text="asdsadas"
android:textStyle="bold"
android:textSize="20sp" >
</TextView>
</LinearLayout>
The problem is the imageviews inside the gridview are being cropped (cut in half), I'm not able to see the whole image. Any solution please ?
将Imageview的android:scaleType属性设置为“ centerCrop”
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.