1

I extend LinearLayout and create my own class GameLinerLayout and then I create class LudoGame that extend that class GameLinerLayout.

Now I try to use it in my layout "main.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"
 android:background="@drawable/background">
</android.game.ludo.LudoGame>

but I can't make it work "background" parameter. So how to set background image on my own view?

I don't understand this. I have my layout and I just want to set the background on that view (there is no other views) and if I do this

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/wood">
<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">
</android.game.ludo.LudoGame>
 </LinearLayout>

It does not display anything and if I set "android:background="#FFFFFF"" on "LudoGame" layout then I see content but without background. Can you show me some example how to resolve this?

Thanks.

That is the same way how my Layout work GameLinerLayout extends LinearLayout And I @Override onDraw method where is object Canvas and where I draw content

@Override
protected void onDraw(Canvas canvas) 
{
    super.dispatchDraw(canvas);
    drawFields(canvas);
}

But I don't want to draw background image with Canvas, I would like (if it possible) to set that background in XML when I try to defined(use) my Layout

Kec
  • 1,435
  • 4
  • 16
  • 21

2 Answers2

1

Take another linear layout inside it. it will work. because you havent defined any background attribute in ur extended class, so better you put another linear layout inside it with fill_parent width and height.!!

mayank_droid
  • 1,015
  • 10
  • 19
  • I try that but then all content in "android.game.ludo.LudoGame" that I draw with canvas is gone (new linerLayoout is over it). How to add that attribute in extended class? I can set that background with canvas but every time I refresh my view it will refresh and that background. Thanks – Kec Sep 13 '11 at 09:34
  • create another xml file with ur extended layout only and add the views which you want to operate on ur main file.just add them in that xml file , so it all be the child view of that extended linearlayout and then you can do with them watever you want to do.. – mayank_droid Sep 13 '11 at 09:40
  • i found you dont need to set the attribute in class of that layout. You can do it easily by setting background in xml file, it happens sometime when u put ur childview as fill_parent in both the width and height. – mayank_droid Sep 13 '11 at 20:02
0

try this: it must work i think.

<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>

create another xml file for this extended layout.

 <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 >

Hope you understand and it helps you...

mayank_droid
  • 1,015
  • 10
  • 19
  • Maybe I'm wrong defined what I need so this is my situation. I have that my new LinerLayout in which I draw shapes, images, rectangles all with Canvas and I can't set background in that my layout, only way that I know is that I draw image (with canvas)before everything in that my layout. So when I use that my layout whatever views that I add later in XML it will be over my layout also over shapes that I draw in it. So maybe solution is that I need to set that background in my layout and not to add some other layouts with background? – Kec Sep 15 '11 at 08:20
  • No. Is't a game there is no "drag and drop" possibility and all game content is in that my layout. – Kec Sep 15 '11 at 10:55
  • I am getting little confised too, i dont understand what you want to do, but have found that you can extend layout and its property programmatically, try this link. http://stackoverflow.com/questions/3885077/relativelayout-programatically-in-android – mayank_droid Sep 15 '11 at 11:10
  • then dont put the child views property fill_parent, put them on wrap_content and then ur extended layout background will not be overlapped by its child view. I hope it must work. – mayank_droid Sep 15 '11 at 11:55