0

I am trying to create a custom gridview item which looks something like how the movies are shown in this image:

enter image description here

in the sense, that how they have an image at the top and two or three text views below it. I have used the following XML code for this but i am not getting the required layout.

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:padding="10dp"
    android:layout_marginBottom="5dp"
    android:background="@drawable/bg_card"
     >

    <TextView
        android:id="@+id/txtTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_marginBottom="2dp"
        android:layout_marginTop="2dp"
        android:gravity="center_vertical"
        android:padding="2dip"
        android:textColor="@color/palletblue"
        android:textAppearance="@android:attr/textAppearanceLarge"
        android:textSize="22sp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/txtTitle2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_marginBottom="2dp"
        android:layout_marginTop="2dp"
        android:layout_below="@id/txtTitle"
        android:gravity="center_vertical"
        android:padding="2dip"
        android:textAppearance="@android:attr/textAppearanceLarge"
        android:textColor="#878787"
        android:textSize="12sp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/txtTitle3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@id/txtTitle2"
        android:layout_marginBottom="2dp"
        android:layout_marginTop="2dp"
        android:gravity="center_vertical"
        android:padding="2dip"
        android:textAppearance="@android:attr/textAppearanceLarge"
        android:textColor="#878787"
        android:textSize="12sp"
        android:textStyle="bold" />
    <ImageView 
        android:id="@+id/imgIcon"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_above="@id/txtTitle"
        android:layout_marginBottom="3dp"
                android:gravity="center_vertical"
                android:padding="2dip"

        />


</RelativeLayout>
</FrameLayout>

Where am i going wrong here? Thanks

Shivam Bhalla
  • 1,879
  • 5
  • 35
  • 63
  • sorry, but your layout is messed up. first of all you dont need the framelyout and a relativelayout doesn't have an orientation. try starting from top. add the image, below that add the textviews and so on, if you don't need a complex layout (things like price and rating) you could use a linearlayout with an vertical orientation.. – malimo Jul 30 '13 at 14:13
  • Hi i tried what you said with an imageview and a textview below it in linear layout, but i am facing some issues where the layout becomes too big and the textview is not visible. Could you give some sample code on how to do it using relative layout? Thanks – Shivam Bhalla Jul 30 '13 at 14:54
  • if the image is too big try to scale it: android:scaleType="centerCrop" i.e. or hardcoding the imageview size / height in dip – malimo Jul 30 '13 at 15:13
  • no the image is fine. there is a lot of unneccesary space around it which is the problem. And also the text is not getting displayed.could you provide some sample code so i can decide where i am going wrong? – Shivam Bhalla Jul 30 '13 at 16:43
  • any thoughts on that? – Shivam Bhalla Jul 31 '13 at 04:48
  • if you provide your current xml i can have a look at it, but i can't do it for you, sorry – malimo Jul 31 '13 at 07:48

0 Answers0