Skip to content Skip to sidebar Skip to footer

Set Text On Button With Button Backround And Text Background Differently

I want to Display image in gridview with a text written on it at bottom. So I took a button and set background on that and set wallpaper on that. This gives a image with a text ov

Solution 1:

Use the following layout for your GridView item :

<RelativeLayoutandroid:layout_width="100dp"android:layout_height="100dp"><ImageViewandroid:id="@+id/img"android:layout_width="match_parent"android:layout_height="match_parent"/><TextViewandroid:id="@+id/caption"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_alignParentBottom="true"android:background="#55000000"android:color="#ffffffff"/></RelativeLayout>

You are not restricted to using a single View as your list item. On Android, it is common to use compound layouts as list items.

The current example consists in overlaying the image itself with a bottom-aligned TextView. Note that the alignment is done on the TextView itself; not the contained text.

Solution 2:

I suggest you 1) Take one Linearlayout instead of button then set Gravity=bottom|centerInHorizontal 2) Take Textview Inside Linearlayout set background to text view and set text wat you want set gravity=center

Thats it..and get LinearLayout Click event...

Solution 3:

Try this way,hope this will help you to solve your problem.

colors.xml

<resources><colorname="transparent_background">#CC4d4d4d</color></resources>

grid_item.xml

<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="wrap_content"android:layout_height="wrap_content"><FrameLayoutandroid:layout_width="100dp"android:layout_height="wrap_content"><ImageViewandroid:layout_width="match_parent"android:layout_height="100dp"android:adjustViewBounds="true"android:src="@drawable/ic_launcher"/><TextViewandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_gravity="bottom"android:gravity="center"android:padding="7dp"android:background="@color/transparent_background"android:text="Games"/></FrameLayout></LinearLayout>

Solution 4:

layout.xml

<RelativeLayoutandroid:id="@+id/RelativeLayout1"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical" ><ImageViewandroid:id="@+id/imageview"android:layout_width="match_parent"android:layout_height="match_parent"android:scaleType="centerCrop" /><LinearLayoutandroid:id="@+id/linear_layout"android:layout_width="match_parent"android:background="@drawable/shadow"android:layout_height="wrap_content"android:layout_alignParentBottom="true"android:orientation="vertical"><TextViewandroid:id="@+id/TextView1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Name"android:textAppearance="?android:attr/textAppearanceLarge" /><TextViewandroid:id="@+id/TextView2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="number"android:textAppearance="?android:attr/textAppearanceSmall" /></LinearLayout></RelativeLayout>

and create shadow.xml

<?xml version="1.0" encoding="utf-8"?><shapexmlns:android="http://schemas.android.com/apk/res/android" ><gradientandroid:angle="270"android:endColor="#33000000"android:centerColor="#11000000"android:startColor="#00000000" /></shape>

Post a Comment for "Set Text On Button With Button Backround And Text Background Differently"