안드로이드 개발할때

LinearLayout 안에 ImageView를 넣을때

XML의 경우에는


<LinearLayout
andorid:id="@+id/la"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<ImageView
android:src="@drawable/소스"
android:layout_marginLeft="5px"
android:layout_marginRight="10px"
android:layout_width="100px"
android:layout_height="150px"

/>
</LinearLayout>



위와 같이 편하게 넣을수 있지만.

java소스에서는 가끔 난감한 경우가 있습니다.

xml의 속성중에 "layout_"가 들어가는 속성은

전부 'LayoutParams' 라는 객체로 설정을 할수있습니다.

위소스 내용에 JAVA소스로 ImageView를 하나더 추가 해보겠습니다.



LinearLayout tmpLay = ( LinearLayout ) findViewById( R.id.la );

ImageView testImg = new ImageView ( getBaseContext() );

//LayoutParams
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams( 100 , 150 );
lp.setMargins( 5 , 0 , 10 , 0 ); // Left, Top, Right, Bottom

testImg.setImageResource( "이미지경로" );

tmpLay.addView( testImg , lp );




이렇게 위와 같은 방법으로 LayoutParams를 추가 할 수 있습니다.


- 태클은 언제나 감사히. -

크리에이티브 커먼즈 라이센스
Creative Commons License
2010/08/12 11:43 2010/08/12 11:43
물론 안드로이드 뿐만 아니라 이클립스에서 프로젝트를 제작 하다보면

가끔씩 전혀 알수 없는 에러가 뜨기도 합니다.

뭐 위치도 알수없고 에러 내용도 알수없는 NullPointerException 이라니.

우선 가장 권장 해볼만한건, 이클립스 메뉴바에 Project - > Clean  해서 해당 프로젝트를 클린 해주시면.

대부분 해결되는 경우가 많습니다~!

참고하세요~!
크리에이티브 커먼즈 라이센스
Creative Commons License
2010/08/05 15:02 2010/08/05 15:02
블로그 이미지

+_+/ Blank Your M.i.n.d_ -Blank