How can I add a TextView into an ImageView in GridView Layout?

后端 未结 3 676
野性不改
野性不改 2021-01-21 22:29

I need a GridView, but in each grid, there will be an ImageView and TextView over/inside it.

It will be like an item image in each grid, and name of the item on the imag

相关标签:
3条回答
  • 2021-01-21 22:53

    Just to extend userSeven7s' answer, you should return the RelativeLayout instead of ImageView, so that the GridView have RelativeLayout as it's direct child, instead of ImageView and RelativeLayout can have TextView and ImageView etc.
    You can get the object of RelativeLayout by the following method:

    RelativeLayout rel = (RelativeLayout)View.inflate(R.layout.YOUR_RELATIVE_LAYOUT_XML_HERE);
    
    0 讨论(0)
  • 2021-01-21 22:55

    Create a RelativeLayout that contains the ImageView and the TextView,with TextView's bottom edge aligned with the Imageview's bottom edge.

    <RelativeLayout ...>
        <ImageView ...>
        <TextView ...
          android:layout_alignBottom="id of the imageview"> // or to top
    </RelativeLayout>
    

    Inflate this layout in getView method of your adapter.

    0 讨论(0)
  • 2021-01-21 23:02
    <RelativeLayout 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >
    
        <ImageView
            android:id="@+id/grid_outer_image"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:src="@drawable/image_border" />
    
        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true" >
    
            <TextView
                android:id="@+id/grid_inner_text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="some text" />
        </RelativeLayout>
    
    </RelativeLayout>
    
    0 讨论(0)
提交回复
热议问题