Here in this layout I want first imageView then textView and then once I complete the textView immediately I want to add imageView, How do I do this.
Asked
Active
Viewed 68 times
-4
-
I have tried with custom FlowLayout but it's taking all above three views in vetical orientation manner How do I do this horizontal manner. – Vinod Pattanshetti Dec 13 '17 at 06:43
3 Answers
1
Try this
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher_round" />
<TextView
android:id="@+id/MyTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="@id/img"
android:gravity="center"
android:text="NILU" />
</RelativeLayout>
Than set Imageview at the end of textview
using ImageSpan
lIke below code
textView = (TextView) findViewById(R.id.MyTextView);
Spannable span = new SpannableString("nilu ");
Drawable demo = getResources().getDrawable(R.mipmap.ic_launcher);
demo.setBounds(0, 0, 50, 50);
ImageSpan image = new ImageSpan(demo, ImageSpan.ALIGN_BASELINE);
span.setSpan(image,span.length()-1,span.length(),Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
textView.setText(span);

AskNilesh
- 67,701
- 16
- 123
- 163
-
No this is not a requirement check the above screenshot carefully. Once I complete the text I need to add immediately imageView. – Vinod Pattanshetti Dec 13 '17 at 06:45
-
-
-
@VinodPattanshetti this will help you https://stackoverflow.com/questions/10696986/how-to-set-the-part-of-the-text-view-is-clickable – AskNilesh Dec 13 '17 at 07:47
-
-
not able achieve click on image because inside .setSpan() method we have to add clickableSpan object where mine is already image object is there. span.setSpan(image,span.length()-1,span.length(),Spannable.SPAN_INCLUSIVE_EXCLUSIVE); any alternative to achieve both functionality. – Vinod Pattanshetti Dec 13 '17 at 12:33
-
0
Use this
android:drawableRight="R.drawabal/xyz"

mehul chauhan
- 1,792
- 11
- 26
-
Please at least at a little bit of explanation why this is the answer to the question, in the current state this is a very low quality answer. – Rolf ツ Dec 13 '17 at 10:50
0
Just add this into your layout file
<?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/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.android.stackoverflow.MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:text="This is your sample text where you can add any
description" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher" />
</LinearLayout>

Nikhil Lotke
- 605
- 7
- 15