안드로이드 개발 질문/답변
(글 수 45,052)
안녕하세요.
메인레이아웃에 ScrollView 와 ScrollView안에 LinearLayout을 앉혔어요ㅠㅠ.
다음 위의 LinearLayout에 Customize한 View를 앉히려고 합니다. 카스톰한 뷰에는 간단히 Image하나만 앉히고 이것을 addView하였는데 ScrollView에 Image가 보이지 않아요ㅠㅠ. 코드는 아래와 같습니다. 무슨 잘못인지 가르쳐 주세요...
public class drawImageInScrollView extends Activity { RelativeLayout mLinearLayout; MyView myView; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); myView = new MyView(getApplicationContext()); mLinearLayout = (RelativeLayout) findViewById(R.id.scrollImageView); // LayoutParams params = new LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT); mLinearLayout.addView(myView, params); } class MyView extends View { Bitmap mBack; public MyView(Context context) { super(context); mBack = BitmapFactory.decodeResource(context.getResources(), R.drawable.ttt); } @Override protected void onDraw(Canvas canvas) { // TODO Auto-generated method stub super.onDraw(canvas); canvas.drawBitmap(mBack, 0,0, null); } } }
main.xml파일은 아래와 같습니다.
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/bbb"> <ScrollView android:id="@+id/scrollView1" android:layout_height="wrap_content" android:layout_width="match_parent"> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/scrollImageView"></RelativeLayout> </ScrollView> </LinearLayout>
저혼자선 아무래도 이유를 모르겠네요... 고수님들 도와주세요.