English 中文(简体)
预产中的相关工资 观点
原标题:RelativeLayout in ScrollView Programmatically

因此,我试图从方案的角度在一份意见书中总结一个相对的解说,但我却发现一个错误,告诉我,相关的解说已经有一个父母。

import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.DatePickerDialog.OnDateSetListener;
import android.os.Bundle;
import android.util.Log;
import android.view.ViewGroup;
import android.widget.DatePicker;
import android.widget.NumberPicker;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.TimePicker;
/*
 * Ids:
 * 1-first Text box
 * 2-DatePicker
 * 3-TimePicker
 */

public class TwoActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //scrollView
        ScrollView sv = new ScrollView(this);

        Log.v("Ro", "Starts app");
        //create Relative Layout
        RelativeLayout rl = new RelativeLayout(this);
        Log.v("Ro", "Relative Layout: "+rl);

        //From Text View
        RelativeLayout.LayoutParams lptv1 = new RelativeLayout.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT);
        lptv1.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
        TextView tv1 = new TextView(this);
        tv1.setText("From: 4-24-12 11:59pm");
        tv1.setId(1);
        rl.addView(tv1, lptv1);

        //To Text View
        RelativeLayout.LayoutParams lptv2 = new RelativeLayout.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT);
        lptv2.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
        TextView tv2 = new TextView(this);
        tv2.setText("To: 4-25-12 12:00am");
        rl.addView(tv2, lptv2);

        //DatePicker
        DatePicker startDate = new DatePicker(this);
        startDate.setId(2);
        RelativeLayout.LayoutParams lptv3 = new RelativeLayout.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT);
        lptv3.addRule(RelativeLayout.BELOW,1);
        rl.addView(startDate, lptv3);

        //TimePicker
        TimePicker startTime = new TimePicker(this);
        startTime.setId(3);
        RelativeLayout.LayoutParams lptv4 = new RelativeLayout.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT);
        lptv4.addRule(RelativeLayout.BELOW,2);
        rl.addView(startTime, lptv4);
        setContentView(rl);

        //NumberPicker
        NumberPicker duration = new NumberPicker(this);
        RelativeLayout.LayoutParams lptv5 = new RelativeLayout.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT);
        lptv5.addRule(RelativeLayout.BELOW,3);
        rl.addView(duration, lptv5);

        sv.addView(rl);

        //setContentView(rl);
        setContentView(sv);
        //setContentView(R.layout.main);
    }
}

它为什么要给我一个问题呢?

最佳回答

You are calling setContentView 2 times. Just remove the first setContentView it should work. Its right above the numberpicker

setContentView(rl);
问题回答

暂无回答




相关问题
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 ...

热门标签