自定义视图不填满屏幕?
问题描述:
当我执行我的Android应用程序时,它工作正常,除了视图不会填满屏幕。我使用下面的XML文件:自定义视图不填满屏幕?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<com.project.name.SplashView
android:id="@+id/splashView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
我有定义的自定义视图,它扩展了常规视图,我重写的onDraw方法来显示一个初始屏幕。在代码中,我用一个简单的通话设置布局:
setContentView(R.layout.splash);
我没有要发布我的onDraw方法,因为它有一堆的动画代码。
private void drawBackground(Canvas c)
{
Paint p = new Paint();
p.setColor(Color.WHITE);
c.drawRect(0, 0, c.getWidth(), c.getHeight(), p);
}
任何人只要有任何想法:不过,我只需出白化使用此功能画布的背景(所以我知道它不是填充屏幕)测试的观点界限?
答
我设法解决通过确保中的minSdkVersion设定为至少8
答
奇怪的是,我把你的代码,并能够使其工作没有问题。我将我的测试编译为2.2,并在2.3.3模拟器上运行。守则规定内嵌之下,作为一个zip这里:
哪个屏幕的面积没有得到正确涂?如果是标题栏和通知区域,然后参考我的意见在下面的清单:
的AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.koderutils.example.customviewfull"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="9" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<!--
NOTE: If you want the Activity to take up the entire screen, add this attribute.
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
-->
<activity
android:label="@string/app_name"
android:name=".ExampleCustomViewFullActivity">
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
ExampleCustomViewFull.java:
package com.koderutils.example.customviewfull;
import android.app.Activity;
import android.os.Bundle;
public class ExampleCustomViewFullActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
CustomView.java:
package com.koderutils.example.customviewfull;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;
public class CustomView extends View {
public CustomView(Context context) {
super(context);
}
public CustomView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onDraw(Canvas c) {
super.onDraw(c);
Paint p = new Paint();
p.setColor(Color.WHITE);
c.drawRect(0, 0, c.getWidth(), c.getHeight(), p);
}
}
的main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<com.koderutils.example.customviewfull.CustomView
android:id="@+id/custom_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
+0
我已经知道标题栏/通知区域,并在我的清单中包含了该主题。它只覆盖了我的屏幕的一部分,右侧和左侧有很少的黑色填充,底部有很多填充。如果我今天有空,我可能会尝试再获得一个截图。 – onit
它看起来像视图应该充满屏幕的问题,但也许你自定义的onDraw方法只有即将它的一部分。你能发布你的onDraw方法的内容吗? – Craigy
@Craigy用更多相关信息更新了问题 – onit