0

i am developing an app where i have to create an xml item in my activity dynamically like circle image view. shown below.

<de.hdodenhof.circleimageview.CircleImageView
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/p_image"
        android:layout_width="120dp"
        android:layout_height="120dp"
        android:src="@mipmap/ic_launcher"
        app:border_width="2dp"
        app:border_color="@android:color/white"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="5dp" />

now in my java code i am creating a new instance of it and i want to change the

app:border_width="2dp"
app:border_color="@android:color/white"

how to do that?

 CircleImageView imageView = new CircleImageView(mContext);
 imageView.border_width="2dp";      //these lines are giving error.
 imageView.border_color="@android:color/white"; //these lines are giving error.
 imageView.setImageResource(mThumbIds[position]);
 imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);

any help will be appriciated thanks :)

1 Answer 1

1

They should have their own getter/setters, you can use them to set values:

imageView.setBorderColor(android.graphics.Color.argb(255, 255, 255, 255)); // Or Color.WHITE for white
imageView.setBorderWidth(2);

You can have a look at how fields are encapsulated at the source code: CircleImageView.java

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.