2

I have 4 TextView: " what is your name?", "in some circumstances" ,you might in some circumstances,you might", "________" and " to help user understand why your app needs a permission.For example " and a Edittext. Now I want create a layout and when I user layout add view in my class ( not file.xml ) it can show same :

enter image description here

I used custom layout same here : Custom RowLayout and add view in code :

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main22);
        int permissionCheck = 
        rowLayout = (RowLayout) findViewById(R.id.row);
        TextView tv1 = new TextView(this);
        tv1.setText("what is your name?");
        rowLayout.addView(tv1);
        EditText ed1 = new EditText(this);
        ed1.setWidth(50);
        rowLayout.addView(ed1);

        TextView tv2 = new TextView(this);
        tv2.setText(" in some circumstances ,you might in some circumstances,you might");
        rowLayout.addView(tv2);
        TextView tv3 = new TextView(this);
        tv3.setText("_____");
        rowLayout.addView(tv3);
        TextView tv4 = new TextView(this);
        tv4.setText("to help user understand why your app needs a permission.For example");
        rowLayout.addView(tv4);
<convert.htv.ex.convertdata.RowLayout
        android:id="@+id/row"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"></convert.htv.ex.convertdata.RowLayout>

and result enter image description here

You can see two problems in here: 1. Edittext not in line with text view. 2. when string text length it create a new line. I want a part off textview will show in old line and when end of the line it will show the rest of textview in newline ( sample picture 1). How I can do it? please help me.

Community
  • 1
  • 1
Trần Hòa
  • 235
  • 4
  • 15

1 Answers1

0

1)Answer for first problem, add this line of code tv1.setGravity(Gravity.CENTER)

2) Change this ed1.setWidth(50); to

ed1.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
MUKUND U
  • 44
  • 6