Android 애플리케이션에서 작업 중이며 해결할 수없는 몇 가지 문제가 있습니다.EditText를 동적으로 삽입 할 때 높이가있는 Android 문제
xml에서 RelativeLayout
은 하나는 EditText
이고 동적으로 변수 값에 따라 하나 또는 두 개의 EditText
을 동적으로 삽입해야합니다.
문제
문제는 그 첫 번째 (XML 선언 한) 상기 하나 EditText
를 삽입 할 때, 그것은, I는 그것의 끝을 확인하고, I없는 너무 높이를 얻을 수 있다는 것이다 왜 일어나는 지 이해할 수 없습니다.
activity.xml
<!-- Some other layouts -->
<RelativeLayout
android:id="@+id/relativeLayoutLectura1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/linearLayoutMensajeLectura"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_marginTop="10dp">
<EditText
android:id="@+id/editTextLectura1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/introducir_lectura"
android:textSize="@dimen/textSize" />
</RelativeLayout>
<!-- More layouts -->
Activity.java
if(lecturas > 1) {
// Have to insert lecturas-1 EditText
RelativeLayout parentLayout = (RelativeLayout)
findViewById(R.id.relativeLayoutLectura1);
for(int lectura = 2; lectura < lecturas; lectura++) {
EditText editTextLectura = new EditText(this);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
if(lectura == 2) {
//Insert below the one created in xml
params.addRule(RelativeLayout.BELOW, R.id.editTextLectura1);
} else {
//Insert below the one created in previous iteration
params.addRule(RelativeLayout.BELOW, lectura-1);
}
editTextLectura.setLayoutParams(params);
editTextLectura.setId(lectura);
editTextLectura.setHint(R.string.introducir_lectura);
editTextLectura.setTextSize(R.dimen.textSize);
//Add to layout
parentLayout.addView(editTextLectura);
}
}
당신이 날 문제를 찾는 데 도움이 있습니다 : 여기
내 코드는 최신인가?이 xml로 작성된 것이 올바르게 표시되고 코드로 작성된 것이 올바른 위치에 설정됩니다.
id가 relativeLayout 인 것은 혼란 스럽습니다. @ + id/linearLayoutLectura1 – ben75
예, 'LinearLayout'을 사용하기 전에'RelativeLayout'으로 변경했을 때 ID를 잊어 버렸습니다. – Lyd