I want to add the style android:layout_marginStart="10pt" into my dynamically created textview:
textswitch.setFactory(new ViewSwitcher.ViewFactory() {
@Override
public View makeView() {
text = new TextView(record_viewer.this);
text.setTextColor(Color.WHITE);
text.setGravity(Gravity.START);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(-2, -2); //throws java.lang.ClassCastException
params.setMargins(10, 0, 0, 0);
text.setLayoutParams(params);
return text;
}
});
How do I proceed?
EDIT: My layout hierarchy is as follwoing:
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout>
<LinearLayout>
<TableLayout>
<TableRow>
<TextSwitcher
android:id="@+id/text_switch"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</TextSwitcher>
<TableRow>
<TableLayout>
</LinearLayout>
</LinearLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
I tried using LinearLayout.LayoutParams but I keep getting the error:
android.widget.LinearLayout$LayoutParams cannot be cast to android.widget.FrameLayout$LayoutParams
I don't get it. Where is FrameLayout in my xml?