많은 게시물을 읽었지만 아무도 내 문제를 해결하지 않았습니다. 또 다른 재미있는 점은 에뮬레이터에서 edittext의 위치가 유지된다는 것입니다 (다른 위젯이 아래로 이동한다는 의미). 그러나 실제 휴대 전화의 동일한 구현에는 위젯의 위치가 표시되지 않습니다. . 나는 TextView
팀 구성원 추가을 클릭하면 EditText
위젯을 동적으로 추가해야하는 다음과 같은 LinearLayout
이 있습니다.LinearLayout에 동적으로 EditText를 추가 할 수 없습니다.
<LinearLayout
android:id="@+id/layout_add_task"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/separator"
android:layout_margin="5dp"
android:background="@color/yellow_background"
android:orientation="vertical"
android:padding="5dp">
<LinearLayout
android:id="@+id/layout_task_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="@+id/iv_check_research_tasks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon_check_empty" />
<EditText
android:id="@+id/et_task_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:selectAllOnFocus="true"
android:text="Task Name"
android:textSize="20dp"
android:textStyle="bold" />
</LinearLayout>
<TextView
android:id="@+id/tv_add_team_member"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginTop="5dp"
android:text="Add a team member"
android:textColor="@color/text_green"
android:textSize="15dp"
android:textStyle="bold" />
<LinearLayout
android:id="@+id/ll_add_task"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/tv_add_team_member"
android:orientation="horizontal"
android:weightSum="100" >
<ImageView
android:id="@+id/iv_create_assignment_attach"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="10"
android:src="@drawable/icon_flag_alt" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="5dp"
android:layout_weight="15"
android:text="Due"
android:textSize="15dp" />
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="65"
android:hint="None"
android:selectAllOnFocus="true" />
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="10"
android:src="@drawable/icon_calendar_empty" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="horizontal" >
<Button
android:id="@+id/btn_create_assignment_trash"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="30dp"
android:layout_marginTop="5dp"
android:text="Trash" />
<Button
android:id="@+id/btn_create_assignment_done"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="5dp"
android:text="Done" />
</LinearLayout>
</LinearLayout>
여기에 Java 코드 인 onClickListener
TextView 구현이 있습니다.
tvAddTeamMember.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
LinearLayout ll = (LinearLayout) getActivity().findViewById(R.id.layout_task_name);
EditText et = new EditText(getActivity());
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
et.setLayoutParams(p);
et.setText("Text");
ll.addView(et);
}
Edittext에 중력을 설정하십시오. – Piyush
@PiyushGupta 중력을 설정하지 않았습니다. –
좋아 .. 그래서 그냥 chk. – Piyush