在Android中设置包含的布局样式

在Android中设置包含的布局样式,android,layout,background,include,Android,Layout,Background,Include,我有两个布局包含功能相同的面板。一个需要一个底部圆角的背景;一个需要一个背景和所有的正方形角落。在所有其他方面,面板应完全相同 是否可以更改包含布局的背景,而不将其包围在或其他包装中?您可以仅为背景创建包装布局,并对所有常用小部件使用 first_layout.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/and

我有两个布局包含功能相同的面板。一个需要一个底部圆角的背景;一个需要一个背景和所有的正方形角落。在所有其他方面,面板应完全相同


是否可以更改包含布局的背景,而不将其包围在
或其他包装中?

您可以仅为背景创建包装布局,并对所有常用小部件使用

first_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width=”match_parent”
    android:layout_height=”match_parent”
    android:background="<FIRST_BACKGROUND>">

    <include layout="@layout/main_layout"/>

</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width=”match_parent”
    android:layout_height=”match_parent”
    android:background="<SECOND_BACKGROUND>">

    <include layout="@layout/main_layout"/>

</LinearLayout>

second_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width=”match_parent”
    android:layout_height=”match_parent”
    android:background="<FIRST_BACKGROUND>">

    <include layout="@layout/main_layout"/>

</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width=”match_parent”
    android:layout_height=”match_parent”
    android:background="<SECOND_BACKGROUND>">

    <include layout="@layout/main_layout"/>

</LinearLayout>


其中main_布局包含所有要重用的组件,因此简而言之,我确实需要
?它可以是任何类型的布局。或者,如果希望以编程方式执行,可以尝试yourLayout.setBackgroundDrawable或yourLayout.setBackgroundResource方法。True:)我希望如果可能,不要使用封闭元素,因为我听说它会减慢布局。我还听说它是最快的布局之一,因此我可能会使用它。谢谢是的,使用包装器布局将在层次结构中再创建一个视图。背景选择基于什么?它只是由我使用的布局静态决定的。在这两种情况下,它都是
下的元素。我现在将包含的布局包装到
中。