-1

I have 3 views, 2 TextViews and 1 ImageView. I want the views to be aligned one after another like below :-

Here the "+" sign is an ImageView and "Another Text" is the second TextView. enter image description here

I tried using a LinearLayout with horizontal orientation. Also RelativeLayout , but the First TextView shows but the next ImageView and the TextView do not show.

<android.support.v7.widget.LinearLayoutCompat
            style="@style/style_ww"
            android:orientation="horizontal">

            <android.support.v7.widget.AppCompatTextView
                android:id="@+id/txtusername"
                style="@style/style_ww"
                android:text="jjjkcrhwkjehrckwjherkjwherckjwhekrcjwernwjkrncwjknrkwjncwjrnwkjcnkwjnrckwjnrkwjnrkwjcncrkjwnrkjcwnrnwkrcnkwnrkwnrckwjnrkwjncrknwkrjnckwnrkwjnrkcwnrkwnckjnrkwnrkwnrckwnrkwnrckwrn"
                android:textColor="@color/colorBlueGrey400"
                android:textSize="@dimen/size_fourteen"
                app:fontFamily="@font/roboto"/>

            <android.support.v7.widget.AppCompatImageView
                android:id="@+id/plus"
                android:layout_width="@dimen/value_2"
                android:layout_height="@dimen/value_2"
                android:layout_gravity="center_vertical"
                android:layout_marginLeft="@dimen/value_5"
                android:layout_marginTop="@dimen/value_1"
                android:src="@drawable/ic_plus"/>

            <android.support.v7.widget.AppCompatTextView
                android:id="@+id/tvcomment"
                style="@style/style_ww"
                android:layout_gravity="center_vertical"
                android:layout_marginLeft="@dimen/value_5"
                android:layout_marginRight="@dimen/value_20"
                android:text="@string/comment"
                android:textColor="@color/colorBlueGrey400"
                app:fontFamily="@font/roboto"/>

        </android.support.v7.widget.LinearLayoutCompat>

style/style_ww

<style name="style_ww">
    <item name="android:layout_height">wrap_content</item>
    <item name="android:layout_width">wrap_content</item>
</style>

How can I achieve this? Any help is appreciated

AskNilesh
  • 67,701
  • 16
  • 123
  • 163
user3034944
  • 1,541
  • 2
  • 17
  • 35

1 Answers1

0

Thanks to Nilesh Rathod below is a solution

tvText = findViewById(R.id.tvText); 


SpannableStringBuilder spannableStringBuilder= new SpannableStringBuilder(); 
Spannable span = new SpannableString("Please press the button looking like this and then proceed .."); 
Drawable test = getResources().getDrawable(R.drawable.ic_delete); 
test.setBounds(0, 0, 32,32); 
ImageSpan imageSpan = new ImageSpan(test, ImageSpan.ALIGN_BASELINE); 
span.setSpan(imageSpan, span.length()-2, span.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE); 
spannableStringBuilder.append(span); 
spannableStringBuilder.append("Second Span"); 


tvText.setText(spannableStringBuilder);
user3034944
  • 1,541
  • 2
  • 17
  • 35