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

java코드로 LinearLayout 알려주세요

0 추천
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    tools:context="com.databar.MainActivity" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="2" >
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="8"
        android:id="@+id/llayout"
        android:orientation="horizontal"
        android:background="@drawable/rectangle" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="vertical"
            android:id="@+id/llayout1"
            android:background="@drawable/rectangle_1" >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1" >

                <TextView
                    android:id="@+id/lat"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:gravity="right|center"
                    android:text="위도" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1" >

                <TextView
                    android:id="@+id/lng"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:gravity="right|center"
                    android:text="경도" />
            </LinearLayout>
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="vertical"
            android:id="@+id/llayout2"
            android:background="@drawable/rectangle_1" >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="@drawable/rectangle_1" >

                <TextView
                   
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:gravity="left|center"
                    android:layout_weight="1"
                    android:text=" SOG" />
                <TextView
                    android:id="@+id/sog"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:gravity="right|center" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1" >

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:gravity="left|center"
                    android:text=" COG" />

                <TextView
                    android:id="@+id/cog"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:gravity="right|center" />
            </LinearLayout>
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="vertical"
            android:id="@+id/llayout3"
            android:background="@drawable/rectangle_1" >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="@drawable/rectangle_1" >

                <TextView
                    android:id="@+id/track"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:gravity="left|center"
                    android:text="TRACK" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                >

                <TextView
                    android:id="@+id/wpt"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:gravity="left|center"
                    android:text="WPT" />
            </LinearLayout>
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="vertical"
            android:id="@+id/llayout4" >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="@drawable/rectangle_1" >

                <TextView
                    android:id="@+id/Date"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:gravity="left|center"
                    android:text="날짜"
                    android:textSize="13sp" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1" >

                <TextView
                    android:id="@+id/suName"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:gravity="left|center"
                    android:layout_weight="1"
                    android:text="수신도" />
                <TextView
                    android:id="@+id/su"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:gravity="right|center"
                    android:layout_weight="1"
                    android:text="수신도" />
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>

</LinearLayout>

 

여기서 메뉴 버튼을 이용해서 리니어레이아웃을 두칸 아니면 세칸 으로 자바코드로 구현할려고해요 그런데

여기서 계속 막히더라구요

llLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,8));
            llLayout1.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1));
            llLayout2.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1));
            llLayout3.removeAllViews();
            llLayout4.removeAllViews();

이렇게 구현하는게 아닌가요..? 이렇게하면 3번이랑 4번만 안에 내용만 없어져요

저는 아예레이아웃 통째로 없애버리고 싶은데 부탁드립니다
문어야 (300 포인트) 님이 2015년 12월 21일 질문

1개의 답변

0 추천
 
채택된 답변

무슨 내용인지 이해하기가 약간 어려우나..

리니어를 생성하는것은 별로 어려운것이 아닐테고..

생성한 리니어를 부모뷰에 붙이는것은 부모뷰.addview()로 자식들을 생성하면되고,

뷰들을 전부 삭제 하고싶으면 부모뷰.removeAllViews(); 로 하시면 됩니다.

removeAllviews는 해당하는 뷰의 자식뷰를 모두 삭제하는 것이기때문에

 llLayout3.removeAllViews();
 llLayout4.removeAllViews();

이 두가지를 사용하면 당연히 3,4번안의 내용만 없어지죠..

저 두가지 뷰를 가지고있는 뷰를 remove해야 합니다..

캬옹이 (37,920 포인트) 님이 2015년 12월 22일 답변
문어야님이 2015년 12월 22일 채택됨
리니어레이아웃안에 텍스트뷰를 원래 있던값을  쓰고싶으면 어떻게해야되나요?
메뉴버튼으로 말그대로 레이아웃만 변경하고싶어요 안에 내용은 그대로고 레이아웃갯수만...
...