I have this layout
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="MyPackage.MainActivity"
tools:showIn="@layout/app_bar_main"
android:id="@+id/content_main">
<TextProgress
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textprogress_day"
android:background="@drawable/layout_border">
</TextProgress>
</android.support.constraint.ConstraintLayout>
I want to create dynamically TextProgerss(My widget) without xml
TextProgress class
public class TextProgress extends ConstraintLayout {
private TextView mTextView;
private ProgressBar mProgressBar;
public TextProgress(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
this.setBackgroundColor(Color.GREEN);
initializeViews(context);
}
.
.
.
I tried below code
ConstraintLayout cl= (ConstraintLayout) findViewById(R.id.content_main);
TextProgress tp=new TextProgress(this,null);
ConstraintLayout.LayoutParams tpParams=new ConstraintLayout.LayoutParams(
ConstraintLayout.LayoutParams.MATCH_PARENT,ConstraintLayout.LayoutParams.WRAP_CONTENT);
tp.setLayoutParams(tpParams);
cl.addView(tp);
But MATCH_PARENT does not work right
and I don't know, how to create dynamically below atrribute
android:background="@drawable/layout_border"