在网上搜索并尝试找到正确的解决方案后,我终于从聊天中的人那里得到了答案。layout
解决方案是在第一个之上再创建一个,例如给它一个高度10dp
和宽度match_parent
。
这是工作示例:
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/MainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/main_bg"
android:orientation="vertical"
android:padding="5dp"
tools:context=".MainActivity" >
<LinearLayout
android:id="@+id/Box"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/background"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/Border"
android:layout_width="match_parent"
android:layout_height="10dp"
android:layout_weight="0.64"
android:background="@drawable/border"
android:orientation="vertical"
tools:ignore="InefficientWeight" >
</LinearLayout>
<TextView
android:id="@+id/Content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.64"
android:padding="5dp"
android:text="@string/example"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@color/white" />
</LinearLayout>
</LinearLayout>
main_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:top="5dp">
<shape>
<solid android:color="#FF990000" />
</shape>
</item>
</layer-list>
背景.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:top="5dp">
<shape>
<solid android:color="#55000000" />
</shape>
</item>
</layer-list>
边框.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:top="5dp">
<shape>
<solid android:color="#FFFF0000" />
</shape>
</item>
</layer-list>
字符串.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Transparent Views</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="example">Content …</string>
<color name="white">#FFFFFFFF</color>
</resources>
希望它对其他人也有帮助。