如何在窗口管理器中删除或添加LinearLayout?

时间:2015-02-03 04:58:45

标签: android xml android-layout android-linearlayout

我有一个问题。我想从布局中删除某个LinearLayout。但问题是布局是在窗口管理器中。如何删除某个LinearLayout?下面是我的代码:

    params = new WindowManager.LayoutParams(
                        WindowManager.LayoutParams.WRAP_CONTENT,
                        WindowManager.LayoutParams.WRAP_CONTENT,
                        WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
                        WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
                        PixelFormat.TRANSLUCENT);
    params.gravity = Gravity.TOP | Gravity.END;

    if (InputType.TV.equals(inputType)) {
        LayoutInflater layoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = layoutInflater.inflate(R.layout.chcall_tv_atv, null);
        TvLog.d(TAG, "@@@@@ CH CALL");
    }

xml代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/chcall_tv_RelativeLayout01"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/chcall_tv_LinearLayout01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <LinearLayout
            android:id="@+id/chcall_tv_LinearLayout02"
            android:layout_width="236dp"
            android:layout_height="53dp"
            android:background="@color/black" >

            <ImageView
                android:id="@+id/chcall_tv_icon"
                android:layout_width="75dp"
                android:layout_height="47dp"
                android:layout_marginTop="6dp"
                android:src="@drawable/ic_chcall_tv" />

            <LinearLayout
                android:id="@+id/chcall_tv_LinearLayout03"
                android:layout_width="87dp"
                android:layout_height="match_parent"
                android:layout_marginLeft="6dp"
                android:orientation="vertical" >

                <LinearLayout
                    android:id="@+id/chcall_tv_LinearLayout04"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="11dp"
                    android:orientation="vertical" >

                    <TextView
                        android:id="@+id/TV"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginBottom="-3dp"
                        android:layout_marginTop="-3dp"
                        android:textColor="@color/white"
                        android:textSize="11dp" />
                </LinearLayout>

                <LinearLayout
                    android:id="@+id/chcall_tv_LinearLayout05"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="3dp"
                    android:orientation="vertical" >

                    <TextView
                        android:id="@+id/tv_input"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="-3dp"
                        android:textColor="@color/white"
                        android:textSize="23dp" />
                </LinearLayout>
            </LinearLayout>

            <LinearLayout
                android:id="@+id/chcall_tv_LinearLayout06"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginRight="8dp"
                android:orientation="vertical" >

                <LinearLayout
                    android:id="@+id/chcall_tv_LinearLayout07"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="23dp"
                    android:orientation="vertical" >

                    <TextView
                        android:id="@+id/tv_airCab"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="-3dp"
                        android:gravity="right"
                        android:textColor="@color/white"
                        android:textSize="11dp" />
                </LinearLayout>

                <LinearLayout
                    android:id="@+id/chcall_tv_LinearLayout08"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="2dp"
                    android:orientation="vertical" >

                    <TextView
                        android:id="@+id/tv_signal"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="-3dp"
                        android:ellipsize="marquee"
                        android:gravity="right"
                        android:marqueeRepeatLimit="marquee_forever"
                        android:singleLine="true"
                        android:textColor="@color/white"
                        android:textSize="11dp" />
                </LinearLayout>
            </LinearLayout>
        </LinearLayout>

        <LinearLayout
            android:id="@+id/chcall_tv_LinearLayout09"
            android:layout_width="236dp"
            android:layout_height="wrap_content"
            android:background="#7F000000"
            android:orientation="vertical" >

            <LinearLayout
                android:id="@+id/chcall_tv_LinearLayout10"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="11dp"
                android:layout_marginTop="6dp"
                android:orientation="vertical" >

                <TextView
                    android:id="@+id/tv_service_name"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="-3dp"
                    android:textSize="11dp" />
            </LinearLayout>

            <LinearLayout
                android:id="@+id/chcall_tv_LinearLayout11"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="11dp"
                android:layout_marginTop="3dp"
                android:orientation="vertical" >

                <TextView
                    android:id="@+id/program_name"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="-4dp"
                    android:textSize="16dp" />
            </LinearLayout>

            <LinearLayout
                android:id="@+id/chcall_tv_LinearLayout12"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="11dp"
                android:layout_marginTop="7dp" >

                <TextView
                    android:id="@+id/tv_audio_type"
                    android:layout_width="44dp"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="-3dp"
                    android:textSize="11dp" />

                <TextView
                    android:id="@+id/tv_audio"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="4dp"
                    android:layout_marginTop="-3dp"
                    android:textSize="11dp" />
            </LinearLayout>

            <LinearLayout
                android:id="@+id/chcall_tv_LinearLayout13"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="11dp"
                android:layout_marginTop="5dp" >

                <TextView
                    android:id="@+id/tv_video_type"
                    android:layout_width="44dp"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="-3dp"
                    android:textSize="11dp" />

                <TextView
                    android:id="@+id/tv_video"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="4dp"
                    android:layout_marginTop="-3dp"
                    android:textSize="11dp" />
            </LinearLayout>

            <LinearLayout
                android:id="@+id/chcall_tv_LinearLayout14"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="11dp"
                android:layout_marginTop="5dp" >

                <TextView
                    android:id="@+id/tv_cc_type"
                    android:layout_width="44dp"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="-3dp"
                    android:textSize="11dp" />

                <TextView
                    android:id="@+id/tv_cc"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="4dp"
                    android:layout_marginTop="-3dp"
                    android:textSize="11dp" />
            </LinearLayout>

            <LinearLayout
                android:id="@+id/chcall_tv_LinearLayout15"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="9dp"
                android:layout_marginLeft="11dp"
                android:layout_marginTop="5dp" >

                <TextView
                    android:id="@+id/tv_ratings_type"
                    android:layout_width="44dp"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="-3dp"
                    android:ellipsize="marquee"
                    android:marqueeRepeatLimit="marquee_forever"
                    android:singleLine="true"
                    android:textSize="11dp" />

                <TextView
                    android:id="@+id/tv_ratings"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="4dp"
                    android:layout_marginTop="-3dp"
                    android:textSize="11dp" />
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>

</RelativeLayout>

i want to remove chcall_tv_LinearLayout13 and all its content so that chcall_tv_LinearLayout14 will be shift up. i appreciate to any helps here.

1 个答案:

答案 0 :(得分:0)

在其他布局的那个位置为LinearLayout选择根布局,然后您可以使用

chcall_tv_LinearLayout13.setVisibility(View.GONE); 

这将自动调整所有布局。