Reputation: 91
the text should be saved on the image view ?the text should not be defined in the layout folder and should be saved on the image view on the accordingly from the key board ?
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fullimage);
// get intent data
Intent i = getIntent();
// Selected image id
int position = i.getExtras().getInt("id");
ImageAdapter imageAdapter = new ImageAdapter(this);
ImageView imageView = (ImageView) findViewById(R.id.fullimage);
imageView.setImageResource(imageAdapter.mThumbIds[position]);
}
}
Upvotes: 0
Views: 247
Reputation: 3703
You can use Button and use button background to set image.and use text element for adding text on button.
<Button
android:layout_width="wrap_parent"
android:layout_height="wrap_parent"
android:text="YourText"
android:background="@drawable/image"
>
</Button>
According to your requirement you can get text from button and pass it with intent
Upvotes: 0
Reputation: 3104
use framelayout for that .. define both ImageView and TextView and set text on TextView
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/thumbHolder">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/thumbImage"
android:scaleType="fitXY" />
<TextView
android:layout_width="match_parent"
android:layout_height="24dp"
android:id="@+id/titletxt"
android:gravity="center_vertical"
android:maxLines="2"
android:paddingRight="8dp"
android:paddingLeft="8dp"
android:textSize="16sp"
android:layout_gravity="bottom"
android:background="#80000000"
android:textColor="#ffffffff"
android:text="" />
</FrameLayout>
for setting custom font :-
then create a typeface by loading that font :-
Typeface tfBold = Typeface.createFromAsset(getActivity().getAssets(), "fonts/Raleway-Bold.otf");
then set your typeface in textView :-
yourTextView.setTypeface(tfBold);
Upvotes: 1
Reputation: 1526
You can do it using TextView
only. Using drawableTop
, drawableBottom
, drawableLeft
, drawableRight
in the following way.
<TextView
style="@style/layout_wrap"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:paddingRight="5dp"
android:drawableTop="@drawable/flags_00"
android:textColor="@color/text_color_tabs"
android:textStyle="bold"
android:maxLength="3"
android:gravity="center"
android:text="Team B" />
and in the code by the following way
battingTeamFlag.setCompoundDrawablesWithIntrinsicBounds(left, top, right, bottom);
Upvotes: 0
Reputation: 7259
You can either draw the image on a canvas, and then draw the text on the image or else, create a layout via code and set the textview inside the layout and then place the layout on top of the image view with background of the textview set to transparent
Upvotes: 0
Reputation: 188
try this-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:background="@drawable/image">
<LinearLayout
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:textSize="18sp"
android:textStyle="bold"
android:singleLine="true"
android:text="text"/>
</LinearLayout>
</LinearLayout>
Upvotes: 0