Reputation: 5954
I have set gridview with 2 columns the values are coming up properly but when showing the text, if the text is goes to the second line the column 1 size is small and column 2 size is bigger. I am not sure why this is happening? I have set everything Match_Parent.
This is will give an idea of what I trying to say:
Did you notice the red circle. Row number 3, column 1 is smaller compared to Row number 3 column 2 why? How to make all the column to stay same?
Here is my gridview.xml :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:background="@android:color/darker_gray"
android:orientation="vertical"
tools:ignore="ContentDescription,RtlHardcoded,NestedWeights" >
<TextView
android:id="@+id/noData"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="@string/nocontantdata"
android:textColor="#000000"
android:textSize="18sp"
android:textStyle="italic"
android:visibility="gone" />
<GridView
android:id="@+id/gridView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:horizontalSpacing="2dp"
android:numColumns="2"
android:scrollbars="vertical"
android:verticalSpacing="2dp"
android:visibility="visible" >
</GridView>
<ImageView
android:id="@+id/imagefooter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@drawable/footer_band"
tools:ignore="ObsoleteLayoutParam" />
</RelativeLayout>
And my itemsRow.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/itemsLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/layoutbackground"
android:gravity="center">
<ImageView
android:id="@+id/profileImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:background="@drawable/friends"
android:paddingBottom="5dp"
android:paddingTop="5dp" />
<TextView
android:id="@+id/profileText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/profileImage"
android:gravity="center"
android:paddingTop="5dp"
android:textColor="@color/blackText"
android:text="@string/profile_text"
android:textSize="16sp" />
</RelativeLayout>
What could be wrong here?
Thanks!
Upvotes: 0
Views: 757
Reputation: 21
If all you want is to keep the items the same size, you can make only one line of text visible. Change/add the parameter maxlines = 1 to your textView and this will keep them all the smaller size. The Relative layout height for your items should be set to wrap-content, not sure if this will make a difference thou.
Upvotes: 1
Reputation: 699
Do this :
<?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:id="@+id/itemsLayout"
android:layout_width="match_parent"
android:layout_height="150dp"
android:orientation="vertical"
android:background="@color/layoutbackground"
android:gravity="center">
<ImageView
android:id="@+id/profileImage"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginTop="10dp"
android:background="@drawable/friends"
android:paddingBottom="5dp"
android:paddingTop="5dp" />
<TextView
android:id="@+id/profileText"
android:layout_width="match_parent"
android:layout_height="50dp"
android:gravity="center"
android:paddingTop="5dp"
android:textColor="@color/blackText"
android:text="@string/profile_text"
android:textSize="16sp" />
</LinearLayout>
Upvotes: 1