对于某些屏幕尺寸,Android自定义视图无法延伸到全屏

时间:2012-07-06 07:14:52

标签: android fullscreen android-linearlayout custom-view

我希望我的应用程序能够使用android拉伸功能在所有屏幕尺寸上全屏运行 我只使用一种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: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>

但是当我在WVGA00(480x800)上运行应用程序时,最右边会显示一个黑条,宽度约为80像素,应用程序不会填满整个屏幕。

课程扩展视图

public class CC_480x320 extends View implements Runnable{

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

关于如何让它在全屏运行的任何想法?

2 个答案:

答案 0 :(得分: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 ???

答案 1 :(得分:0)

math_parent应该在根布局参数中使用,而不是在子布局参数中使用。希望在子视图中使用fill_parent。

我之前没有使用过画布。但我猜它就像一个ImageView。如果图像的实际像素小于屏幕的像素,则ImageViews实际上不会渲染到全屏。如果是这种情况,那么你必须使用缩放,或适当的画布。

此外,如果您尝试查看全屏而不是画布,但整个应用程序尝试更新清单中的主题。在申请部分:

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

更新:

根据您的屏幕截图是缩放效果。更改画布的缩放效果。尝试搜索如何将画布的比例设置为您查看的布局参数。删除你的体重属性并先测试

问题:你在layout.xml上添加了其他内容吗?像一个观点或什么?