I want the alignment of the editext and the imageviewin the same horizontal line but I am getting the imageview below the edittext.
main fragment code
final LinearLayout lnrView = (LinearLayout)
child.findViewById(R.id.lnrView);
Button btnad = (Button) child.findViewById(R.id.btnad);
btnad.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
lnrView.addView(newedittext());
lnrView.addView(newImageview(getActivity()));
}
});
neweditext method
private View newedittext() {
final ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
final EditText editText = new EditText(getActivity());
int id = 0;
editText.setId(id);
editText.setTextSize(14);
editText.setTextColor(Color.rgb(0, 0, 0));
editText.setMaxEms(2);
editText.setInputType(InputType.TYPE_CLASS_TEXT);
return editText;
}
newImageview method
public ImageView newImageview(Context context) {
final ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
final ImageView imgView = new ImageView(context);
int id = 0;
imgView.setId(id);
imgView.setImageDrawable(context.getResources().getDrawable(R.drawable.ic_close_red));
return imgView;
}
main fragment xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:id="@+id/btnad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="add" />
<LinearLayout
android:id="@+id/lnrView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
</LinearLayout>
when i click the Add button an edittext and Imageview is created dynamically and my output screen look like below
i want the imageview
and the edittext
in the same line. can anyone help me.
when i add "Horizontal" this is the output
this my expected result
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…