0

i have two textviews in relative layout. first textview size is fixed and second textview size is dynamic. I want my second textview to fill all available width want output like thisbut i am unable to do this. is it possible? this is what i am getting right now

My xml :

 <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/ten_dp">

        <com.staff_have_says.utitlies.MyTextViewBold
            android:id="@+id/banner"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Massage To Management"
            android:background="@android:color/holo_green_dark"
            android:padding="@dimen/ten_dp"
            android:textColor="@color/white"
         />

        <TextView

            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toEndOf="@id/banner"
            android:text="Flaticon Basic License. It's necessary to credit the author.  How to credit the authorship of the icons?Flaticon Basic License. It's necessary to credit the author.  How to credit the authorship of the icons?"

            />
    </RelativeLayout>
jatin rana
  • 825
  • 1
  • 9
  • 21

1 Answers1

2

You can use a single TextView for both sections of your content with SpannableString as a text. See example.

pawegio
  • 1,722
  • 3
  • 17
  • 29
  • thanks. i followed your method and i am able to achieve the desired ouput but how to set padding to background color span. – jatin rana Oct 17 '16 at 11:36
  • my code: String resposne="Flaticon Basic License. It's necessary to author. How to credit the authorship of the icons?"; SpannableString styledString = new SpannableString("Massage To Management-"+resposne); styledString.setSpan(new BackgroundColorSpan(Color.GREEN), 0, 21, 0); styledString.setSpan(new RelativeSizeSpan(1.5f), 0, 21, 0); TextView textView = (TextView) rootview.findViewById(R.id.banner); textView.setText(styledString); – jatin rana Oct 17 '16 at 11:36
  • It requires custom `ReplacementSpan` with access to `draw()` method. See [this](http://stackoverflow.com/a/29023947/1432752). – pawegio Oct 17 '16 at 11:43
  • tried that but not working. texts are not in proper place and some text are hiding behind background color. – jatin rana Oct 17 '16 at 12:50
  • Working well for single line text but not for multi line texts. – jatin rana Oct 17 '16 at 12:52