English 中文(简体)
Android 相对 Layout 股 试验装置
原标题:Android s RelativeLayout Unit Test setup
  • 时间:2010-03-20 03:43:58
  •  标签:
  • android

i m 试图为我的安纳塞利乌特撰写一个单位测试。 目前,我的测试编码如下:

public class SampleRelativeLayoutTest extends AndroidTestCase {

private ViewGroup testView;

private ImageView icon;
private TextView  title;


@Override
protected void setUp() throws Exception {
    super.setUp();
    // inflate the layout
    final Context context = getContext();
    final LayoutInflater inflater = LayoutInflater.from(context);
    testView = (ViewGroup) inflater.inflate(R.layout.sample_layout,
            null);
    // manually measure and layout
    testView.measure(500, 500);
    testView.layout(0, 0, 500, 500);
    // init variables
    icon = (ImageView) testView.findViewById(R.id.icon);
    title = (TextView) testView.findViewById(R.id.title);
}

然而,我遇到了Null PointerException,其分寸如下:

java.lang.NullPointerException
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:427)
at android.view.View.measure(View.java:7964)
at com.dqminh.test.view.SampleRelativeLayoutTest.setUp(SampleRelativeLayoutTest.java:33)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:430)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1447)

我应当修改一下我的定点代码,使测试能够适当进行?

最佳回答

我拿到一份安乐来源的复印件,但并不肯定它是否与你所重复(或者说这几类事情确实如此)。 唯一的例外是,在Measure方法中,在427条下,采用相关语言。 我版本中的这一行程是Measure方法中马卢埃帕拉姆病例变量的首批准入。 难道你会想在你们的Xml布局或像这样的东西中增加布局——宽和布局。

问题回答

如果你在“线索”内总结你的亲子关系,你也将工作。 相反,通过“线”

我将做这项工作:

LayoutParams layoutParams = new LayoutParams(500,500);
testView.setLayoutParams(layoutParams);
testView.layout(0, 0, 500, 500);

另一个可能的原因是:你在<代码>中途经与子女状况之间有循环依赖。 例如,您有<代码>RelativeLayout。 身高限为WRAP_CONTENT,及儿童组为ALIGN_PARENT_BOTTOM

下面是<代码>的说明。 RelativeLayout:

A Layout where the positions of the children can be described in relation to each other or to the parent. For the sake of efficiency, the relations between views are evaluated in one pass, so if view Y is dependent on the position of view X, make sure the view X comes first in the layout.

请注意,你无法在<代码>RelativeLayout的大小与子女的地位之间有循环依赖。 例如,你不能有<代码>RelativeLayout。 身高限为WRAP_CONTENT,及儿童组为ALIGN_PARENT_BOTTOM

排外特性见<代码>RelativeLayout.LayoutParams。





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签