0

问题

我使用下面的代码膨胀了一些布局以添加到现有布局中。

API = 19 中似乎一切正常但是,低于 19 则不行。

我不知道这里发生了什么请帮我找出问题thx。

示例图片

示例图像

添加任何视图之前的默认视图

添加任何视图之前

示例代码

    LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View v = inflater.inflate(R.layout.temp_added_layout, null, false);

    LinearLayout llFirstDevice = (LinearLayout) findViewById(R.id.llFirstDevice);
    if (android.os.Build.VERSION.SDK_INT < 16) {
        llFirstDevice.setBackgroundResource(R.drawable.temp_top_added);
    } else {
        llFirstDevice.setBackground(getResources().getDrawable(R.drawable.temp_top_added));
    }
    llFirstDevice.addView(v, 0);

添加任何视图之前的默认视图 XML 布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">


    <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="0dp" android:layout_weight="1" android:background="@drawable/temp_top_blank"
            android:gravity="center" android:id="@+id/llFirstDevice">
        <RelativeLayout
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="fill_parent" android:gravity="center">
            <LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content" android:gravity="center">
                <ImageView
                        android:layout_width="30dp"
                        android:layout_height="30dp"
                        android:src="@drawable/ic_content_new" android:scaleType="fitXY"
                        android:layout_alignParentLeft="true"
                        android:layout_alignParentTop="true"/>
                <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="match_parent"
                        android:text="A/C Node"
                        android:textSize="15sp"
                        android:textColor="#333333"
                        android:shadowColor="#7F000000"
                        android:shadowDx="-1"
                        android:shadowDy="-1"
                        android:shadowRadius="1" android:gravity="center" android:layout_alignParentLeft="true"
                        android:layout_alignParentTop="true"/>
            </LinearLayout>
        </RelativeLayout>
    </LinearLayout>
    <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="0dp" android:layout_weight="1" android:background="@drawable/temp_mid_blank"
            android:id="@+id/llSecondDevice" android:gravity="center">

        <RelativeLayout
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="fill_parent" android:layout_gravity="center_vertical">
            <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent"
                          android:layout_height="wrap_content" android:gravity="center"
                          android:layout_centerVertical="true" android:layout_alignParentLeft="true"
                          android:layout_alignParentStart="true">
                <ImageView android:layout_width="30dp" android:layout_height="30dp"
                           android:src="@drawable/ic_content_new" android:scaleType="fitXY"
                           android:layout_alignParentLeft="true" android:layout_alignParentTop="true"/>
                <TextView android:layout_width="wrap_content" android:layout_height="match_parent"
                          android:text="A/C Node" android:textSize="15sp"
                          android:textColor="#333333" android:shadowColor="#7F000000" android:shadowDx="-1"
                          android:shadowDy="-1" android:shadowRadius="1" android:gravity="center"
                          android:layout_alignParentLeft="true" android:layout_alignParentTop="true"/>
            </LinearLayout>
        </RelativeLayout>

    </LinearLayout>
    <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="0dp" android:layout_weight="1" android:background="@drawable/temp_bot_blank"
            android:gravity="center" android:id="@+id/llThirdDevice">
        <RelativeLayout android:orientation="horizontal" android:layout_width="match_parent"
                        android:layout_height="fill_parent" android:gravity="center">
            <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent"
                          android:layout_height="wrap_content" android:gravity="center">
                <ImageView android:layout_width="30dp" android:layout_height="30dp"
                           android:src="@drawable/ic_content_new" android:scaleType="fitXY"
                           android:layout_alignParentLeft="true" android:layout_alignParentTop="true"/>
                <TextView android:layout_width="wrap_content" android:layout_height="match_parent"
                          android:text="A/C Node" android:textSize="15sp"
                          android:textColor="#333333" android:shadowColor="#7F000000" android:shadowDx="-1"
                          android:shadowDy="-1" android:shadowRadius="1" android:gravity="center"
                          android:layout_alignParentLeft="true" android:layout_alignParentTop="true"/>
            </LinearLayout>
        </RelativeLayout>
    </LinearLayout>
</LinearLayout>

R.Drawable.temp_top_added

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
        <shape>
            <solid android:color="#7e3f9e" />
        </shape>
    </item>
    <item
            android:left="20dp"
            android:top="10dp"
            android:right="20dp"
            android:bottom="10dp">
        <shape >
            <stroke
                    android:dashGap="10dp"
                    android:dashWidth="10dp"
                    android:width="2dp"
                    android:color="#99333333" />
            <padding
                    android:bottom="@dimen/temp_added_padding_B"
                    android:left="30dp"
                    android:right="30dp"
                    android:top="@dimen/temp_added_padding_T" />
        </shape>
    </item>
</layer-list>
4

1 回答 1

0

只需将您的形状编辑为:

<shape >
    <stroke
        android:dashGap="10dp"
        android:dashWidth="10dp"
        android:width="2dp"
        android:color="#99333333" />
    <padding
        android:bottom="@dimen/temp_added_padding_B"
        android:left="30dp"
        android:right="30dp"
        android:top="@dimen/temp_added_padding_T" />
    <solid android:color="@android:color/transparent"/> <!-- ADD THIS LINE -->
</shape>
于 2014-08-13T15:44:35.773 回答