2

When I click the add button to add a new view, everything but images are displaying on the screen. I tried different images in different positions. But nothing worked.

    public void onClick(View view) {

        LayoutInflater vi = null;
        vi = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        
        View v = vi.inflate(R.layout.news_views, null);
        
        ViewGroup insertPoint = (ViewGroup) findViewById(R.id.allNews);
        insertPoint.addView(v, 0, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
    }

This is the method I am using and news_views is the layout I am using to add a new news on the main screen.

enter image description here

To show that it is actually there I added a background color.

enter image description here

And also when there is no background it makes space, so it is there but not really :/

This is the .xml file of the news_views:

<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/news_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/grey_round"
    android:padding="15dp">

    <TextView
        android:id="@+id/textView"
        android:layout_width="300dp"
        android:layout_height="wrap_content"
        android:text="Heading Is Just Right Here"
        android:textColor="#FFFFFF"
        android:textSize="24sp" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="300dp"
        android:layout_height="wrap_content"
        android:layout_row="1"
        android:layout_column="0"
        android:text="This is going to be a preview for the user to understand what is about this article."
        android:textColor="#FFFFFF"
        android:textSize="18sp" />

    <ImageView
        android:id="@+id/upvoteIcon"
        android:layout_width="20dp"
        android:layout_height="20dp"
        android:layout_row="2"
        android:layout_column="2"
        app:srcCompat="@android:drawable/arrow_up_float" />
doguzkaan
  • 33
  • 5
  • Hello and welcome! Your question looks to be pretty good. I think it would be very helpful to answerers and future readers if you made your title more specific. :) – Beefster Dec 17 '20 at 20:26

1 Answers1

1

The reason behind the error is in news_views.xml file. The vector drawable is tried to be set as source of ImageView using srcCompat attribute. If it is intended to use srcCompat attribute, build.gradle file should contain vectorDrawables.useSupportLibrary = true line of code.

Or src attribute may be used instead of srcCompat attribute.

It is indicated and explained in detail here. You can look at the link for more information about the src and srcCompat .

gxslash
  • 135
  • 1
  • 12