0

I am expecting my app to run in fullscreen on all screen sizes using the android stretching capabilities Am using only one XML layout.

  <?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:orientation="horizontal" >

    <com.nwm.CD.CCanvas_480x320
         android:layout_weight ="1"
         android:fillViewport="true"
         android:id="@+id/cc_320x480"
         android:layout_width="match_parent"
         android:layout_height="match_parent"/>
</LinearLayout>

But when I run the app on a WVGA00(480x800) a black bar shows up on the far right and has a width of about 80pixels and the app doesn't fill the entire screen.

The class extending view

public class CC_480x320 extends View implements Runnable{

    public CricCanvas_480x320(Context context, AttributeSet attrs) {
         super(context, attrs);
     this.context = (CricDhamaka)context;
    }

Any ideas on how to make it run in fullscreen??

Ram
  • 13
  • 4

2 Answers2

0
Display displayDevice=getWindowManager().getDefaultDisplay();
        int wid=displayDevice.getWidth();
        int hit=displayDevice.getHeight();
LayoutParams lp=new LayoutParams(wid, hit);



yourview.setlayoutParams(lp);



have you tried this ???
Aashish Bhatnagar
  • 2,595
  • 2
  • 22
  • 37
  • Yup tried it, no change still getting the black unused space. – Ram Jul 06 '12 at 08:14
  • try assigning hieght and width at runtime using layout params – Aashish Bhatnagar Jul 06 '12 at 08:52
  • I tried this on the oncreate of activity, application doesn't start. – Ram Jul 06 '12 at 09:17
  • I tried this way too, `LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(wid, hit); canvas.setLayoutParams(layoutParams);' Doesnt work too. I have defined the linearlayout layout in the XML and not in the main code, will still declaring"Linearlayout.layoutParam" work?? Or this applies only when Linearlayout is added via code.? – Ram Jul 06 '12 at 09:23
  • you are adding the layout to linear layout or relative?? – Aashish Bhatnagar Jul 06 '12 at 10:28
0

math_parent should be used in root layout parameters and not in child ones. Prefer to use fill_parent in your child views.

I haven't worked with canvas before. But I guess it works like an ImageView. ImageViews don't actually render to full screen if the actual pixels of the image is smaller than the pixels of the screen. If that is the case then you have to use scaling, or the appropriate thing for canvas.

Also if you are trying to view full screen not the canvas but the whole application try to update your theme in your manifest. In the application section:

<application android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
... // removes the title bar of every activity in your application and makes it full screen no battery no signal etc
</application>

UPDATE:

According to your screen shot is the scaling effect. Change the scaling effect of your canvas. Try searching on how to make the scale of your canvas to the layout parameters of you view. Delete your weight attribute and test first though

Question: have you added anything else on your layout.xml? Like a view or something?

10s
  • 1,699
  • 1
  • 12
  • 14
  • Tried the android:theme attribute in the manifest Also changed the match_parent to fill_parent for the child. Still no change! – Ram Jul 06 '12 at 08:13
  • when you say the black unused space what do you mean? The battery and the singal? Or is some kind of view in your layout? Is it that the canvas element does not take full screen? A screen shot might be helpful. – 10s Jul 06 '12 at 08:17
  • The status bar(battery/signal) doesnt get displayed. I am talking about a unstretched space in my view, Doesn't android simply stretch the resources for different screen sizes? Screen shot http://i.imgur.com/o4Sbf.jpg – Ram Jul 06 '12 at 09:08
  • When I try LayoutParams lp=new LayoutParams(wid, hit); view.setlayoutParams(lp); on the oncreate of activity, the app crashes, any idea why? – Ram Jul 06 '12 at 09:32
  • My layout.xml doesnt contain anything other that what I posted in the original post – Ram Jul 06 '12 at 10:24
  • Yes I noticed that too, so I have updated my comment again. You should search about the .scale() method in the canvas element. Despite the view itself is fill parent the canvas element inside it does not take the full width and height of the view because it tries to maintain the scaling. Inside your com.nwm.CD.CCanvas_480x320 View what exactly are you doing? – 10s Jul 06 '12 at 10:25
  • extending the view as mentioned and have used several images to create a game. – Ram Jul 06 '12 at 10:33
  • ok, there is something wrong. Are all your Views attached to the parent View have good layout params. Maybe the outer view that is used as the background has wrap_content or density pixels specified as its layout parameters? – 10s Jul 06 '12 at 10:59