안드로이드 개발할때

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

이 글의 트랙백 주소 - http://www.blanknote.kr/trackback/15

  1. NED [2010/12/15 00:58]  수정/삭제 |  댓글쓰기

    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams( 100 , 150 );
    여기서 100, 150 은 뭘 뜻하는건가요 ?; 으흠;;

    • Blank [2010/12/15 13:29]  수정/삭제

      저게 LayoutParams 인데 Width 랑 Height 설정하는겁니다.

      또는 FILL_PARENT나 WRAP_CONTENT처럼 넣을 수도 있습니다. ^^

이름     비밀번호     홈페이지 또는 블로그

블로그 이미지

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