마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

HorizontalScrollView 안의 LinearLayout 레이아웃 width 프로그래밍 적으로 조절하는 법

0 추천
<HorizontalScrollView
        android:id="@+id/horizontalScrollView1"
        android:layout_width="match_parent"
        android:layout_height="200dp" >

        <LinearLayout
            android:layout_width="900dp"
            android:layout_height="match_parent"
            android:orientation="horizontal" >

            <ImageView
                android:id="@+id/viewImgFront"
                android:layout_width="300dp"
                android:layout_height="200dp"
                android:src="@drawable/icon" />

            <ImageView
                android:id="@+id/viewImgBack"
                android:layout_width="300dp"
                android:layout_height="200dp"
                android:src="@drawable/icon" />
        </LinearLayout>
    </HorizontalScrollView>

 

위와 같은 xml 레이아웃이 있습니다.

프로그래밍 적으로 LinearLayout 의 가로 사이즈를 조절하고 싶은데요..

구글링해서..

HorizontalScrollView h = (HorizontalScrollView)findViewById(R.id.horizontalScrollView1);

h.getChildAt(0).setLayoutParams(new FrameLayout.LayoutParams(300,200));

위와 같이 했는데 에러가 나네요...

조언 부탁드립니다.
부산민지아빠 (220 포인트) 님이 2014년 5월 15일 질문

1개의 답변

+1 추천

LinearLayout 에 id 를 생성 하시고 findViewById 하신 뒤 직접 setLayoutParam 값을 주세요 그리고  ViewGroup.LayoutParams 을 사용하세요

aucd29 (218,390 포인트) 님이 2014년 5월 15일 답변
...