나는 안드로이드에서 UI 디자인에 익숙해 지도록 간단한 프로그램을 작성했습니다. 선형 레이아웃 안에 텍스트를 동적으로 추가했습니다. 내가 logcat에서 어떤 에러도 볼 수없는 코드를 디버깅 할 때, 코드는 완벽하게 잘 돌아 간다. 하지만 내 장치에서 텍스트를 볼 수 없습니다. 나는 갤럭시 S2를 사용하고있다. 나는 또한 에뮬레이터를 사용해 보았다. 그러나 아무것도 나타나지 않았다. 내 장치/에뮬레이터에 텍스트가 표시되지 않는 이유를 모르겠습니다. 도와주세요. 여기 안드로이드에서 선형 레이아웃 내부의 텍스트 뷰를 볼 수 없습니다.
여기 내 main.xml에이 내 활동public class ViewActivity extends Activity {
/** Called when the activity is first created. */
LinearLayout bar;
String myarray[]={"Foot Ball","Basket Ball","Cricket"};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
bar= (LinearLayout) findViewById(R.id.tag);// Map the Layout
bar.setVisibility(View.VISIBLE);
TextView bs_text[]= new TextView[myarray.length]; // Create TextView according to value in length variable;
for(int z=0;z< myarray.length ;z++)
{
try
{
bs_text[z] = (TextView) new TextView(this);
bs_text[z].setText(myarray [z]);
//bs_text[z].setTextSize(1);
bs_text[z].setBackgroundColor(android.graphics.Color.TRANSPARENT);
bs_text[z].setTextColor(android.graphics.Color.BLACK);
int height_in_pixels = bs_text[z].getLineCount() * bs_text[z].getLineHeight(); //approx height text
bs_text[z].setHeight(height_in_pixels);
//bs_text[z].setHeight(android.graphics.)
bar.addView(bs_text[z]);
}
catch(ArrayIndexOutOfBoundsException e)
{
Log.d("ArrayIndexOutOfBoundsException",e.toString());
}
}
}
}
입니다
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tag"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</LinearLayout>
안녕하세요, mithu,이 코드를 사용해 보겠습니다. –