-2

I'm trying to build this view in xml file in android that express a list item in a recyclerview

enter image description here

but I get this view instead

enter image description here

here's my code

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/white"
    android:orientation="horizontal"
    android:padding="5dp">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:orientation="vertical">

        <ImageView
            android:id="@+id/image_news"
            android:layout_width="100dp"
            android:layout_height="100dp"
            app:srcCompat="@drawable/ic_perm_identity_grey_400_48dp" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="left"
        android:orientation="horizontal"
        android:padding="10dp">

        <TextView
            android:id="@+id/txt_news_name"
            android:layout_width="135dp"
            android:layout_height="wrap_content"
            android:layout_marginRight="5dp"
            android:text="Mohamed Alaa"
            android:textColor="@android:color/black"
            android:textSize="18sp" />

        <TextView
            android:id="@+id/txt_news_content"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="added a new photo to the album"
            android:textSize="16sp" />

    </LinearLayout>

</LinearLayout>

How can I improve my code to get the Desired result?

Please I want any answer to be applied in xml files only without writing java code

Michael
  • 411
  • 2
  • 6
  • 15
  • 1
    Why did you put the ImageView alone in a layout? That's really an anti-pattern. Try using a RelativeLayout, to combine alle yout Views in a unique container. – Phantômaxx Dec 10 '17 at 12:23

1 Answers1

0

Do something like this:

TextView tv = (TextView) findViewById(R.id.yourTextView);

String name = "Mohammed Alaa";
String album = "Instagram Photos";

SpannableStringBuilder sb = new SpannableStringBuilder();

sb.append(name,new StyleSpan(android.graphics.Typeface.BOLD),Spannable.SPAN_INCLUSIVE_INCLUSIVE);
sb.append(" added a new photo to the album ");
sb.append(album,new StyleSpan(android.graphics.Typeface.BOLD),Spannable.SPAN_INCLUSIVE_INCLUSIVE);
sb.append(".");

tv.setText(sb);
Ben221199
  • 128
  • 2
  • 8