Android我的线性布局

Android我的线性布局,android,Android,我扩展LinearLayout并创建自己的类gamelinerllayout,然后创建类LudoGame,扩展该类GameLinerLayout 现在我尝试在布局“main.xml”中使用它 但我不想用画布绘制背景图像,我希望(如果可能的话)在尝试定义(使用)我的布局时用XML设置背景。它会起作用的。因为您还没有在扩展类中定义任何背景属性,所以最好在扩展类中放置另一个线性布局,并填充父宽度和高度 在其内部采用另一种线性布局。它会起作用的。因为您还没有在扩展类中定义任何背景属性,所以最好在扩展类

我扩展
LinearLayout
并创建自己的类
gamelinerllayout
,然后创建类
LudoGame
,扩展该类
GameLinerLayout

现在我尝试在布局“main.xml”中使用它


但我不想用画布绘制背景图像,我希望(如果可能的话)在尝试定义(使用)我的布局时用XML设置背景。它会起作用的。因为您还没有在扩展类中定义任何背景属性,所以最好在扩展类中放置另一个线性布局,并填充父宽度和高度


在其内部采用另一种线性布局。它会起作用的。因为您还没有在扩展类中定义任何背景属性,所以最好在扩展类中放置另一个线性布局,并填充父宽度和高度


试试这个:我想它一定有用

<android.game.ludo.LudoGame xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/ll_absolute"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/wood">
     </LinearLayout>
</android.game.ludo.LudoGame>

为此扩展布局创建另一个xml文件

 <android.game.ludo.LudoGame xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/ll_absolute"
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"> 
// now add all the views(not layouts) here, u want to create them with same id in both file
</android.game.ludo.LudoGame >

//现在在这里添加所有视图(而不是布局),您希望在这两个文件中创建具有相同id的视图

希望你能理解,它能帮助你……

试试这个:我想它一定有用

<android.game.ludo.LudoGame xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/ll_absolute"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/wood">
     </LinearLayout>
</android.game.ludo.LudoGame>

为此扩展布局创建另一个xml文件

 <android.game.ludo.LudoGame xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/ll_absolute"
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"> 
// now add all the views(not layouts) here, u want to create them with same id in both file
</android.game.ludo.LudoGame >

//现在在这里添加所有视图(而不是布局),您希望在这两个文件中创建具有相同id的视图

希望你能理解,这对你有帮助……

我试过了,但是我用画布绘制的“android.game.ludo.LudoGame”中的所有内容都不见了(新的LinerLayout就在上面了)。如何在扩展类中添加该属性?我可以用画布设置背景,但每次我刷新视图时,它都会刷新背景。感谢您仅使用扩展布局创建另一个xml文件,并添加您要在主文件上操作的视图。只需将它们添加到该xml文件中,使其成为扩展线性布局的子视图,然后您就可以随心所欲地处理它们。我发现您不需要在该布局的类中设置属性。您可以通过在xml文件中设置背景来轻松实现这一点,当您将您的childview作为宽度和高度的填充父视图时,有时会发生这种情况。我尝试过这样做,但随后我用画布绘制的“android.game.ludo.LudoGame”中的所有内容都消失了(新的LinerLayout已经覆盖)。如何在扩展类中添加该属性?我可以用画布设置背景,但每次我刷新视图时,它都会刷新背景。感谢您仅使用扩展布局创建另一个xml文件,并添加您要在主文件上操作的视图。只需将它们添加到该xml文件中,使其成为扩展线性布局的子视图,然后您就可以随心所欲地处理它们。我发现您不需要在该布局的类中设置属性。通过在xml文件中设置背景,你可以很容易地做到这一点。有时候,当你把你的childview作为填充父视图的宽度和高度时,就会发生这种情况。也许我对我需要的东西定义错误,所以这就是我的情况。我有一个新的LinerLayout,我用画布绘制形状、图像、矩形,我不能在我的布局中设置背景,我知道的唯一方法是在布局中的所有内容之前绘制图像(用画布)。因此,当我使用我的布局时,无论我稍后在XML中添加什么视图,它都将覆盖我的布局,也覆盖我在其中绘制的形状。所以,也许解决方案是我需要在我的布局中设置背景,而不是添加一些其他背景布局?不,这不是一个游戏,没有“拖放”的可能性,所有游戏内容都在我的布局中。我也不太自信,我不明白你想做什么,但如果您发现可以通过编程方式扩展布局及其属性,请尝试以下链接。然后不要把子视图属性fill\u parent放在wrap\u content上,这样扩展的布局背景就不会与其子视图重叠。我希望它能起作用。也许我对我需要的东西定义错误,所以这就是我的情况。我有一个新的LinerLayout,我用画布绘制形状、图像、矩形,我不能在我的布局中设置背景,我知道的唯一方法是在布局中的所有内容之前绘制图像(用画布)。因此,当我使用我的布局时,无论我稍后在XML中添加什么视图,它都将覆盖我的布局,也覆盖我在其中绘制的形状。所以,也许解决方案是我需要在我的布局中设置背景,而不是添加一些其他背景布局?不,这不是一个游戏,没有“拖放”的可能性,所有游戏内容都在我的布局中。我也不太自信,我不明白你想做什么,但如果您发现可以通过编程方式扩展布局及其属性,请尝试以下链接。然后不要把子视图属性fill\u parent放在wrap\u content上,这样扩展的布局背景就不会与其子视图重叠。我希望它能起作用。
 <android.game.ludo.LudoGame xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/ll_absolute"
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"> 
// now add all the views(not layouts) here, u want to create them with same id in both file
</android.game.ludo.LudoGame >