0

我在我的代码中设置了通知侦听器。每当我收到通知时,我都想在我的linear layout活动中放置一个文本视图,该视图最初没有任何内容。
当第二个通知到达时,我想在前一个文本视图下方再添加一个文本视图。

public class InformationActivity extends Activity
{

    public static VideoInformationClass vidInfo = new VideoInformationClass() ;
    public static LinearLayout lv ;
    public static LayoutParams textViewParams;
    public static TextView tv ;
    public static TextView tv1,tv2,tv3,tv4,tv5,tv6,tv7,tv8,tv9,tv10;
    static int fieldFrequency;
    static int numberOfFrameLines;
    static int numberOfVisibleLines;
    static int numberOfVisiblePixels;
    static int interlace;
    static int imageFormat;
    static int videoCoding;
    static int scanType;

    VideoPropertiesParams GetParams;

    VideoPropertiesParams VP;

@Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.information_activity);

        Context context = getBaseContext();
        LinearLayout lv = new LinearLayout(this);
        lv.setOrientation(LinearLayout.VERTICAL);
        LinearLayout.LayoutParams textViewParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
       // tv = new TextView(this);


    }

@Override
protected void onStart() {
    // TODO Auto-generated method stub
    super.onStart();
    onFieldFrequencyChanged();
    onImageFormatChanged();
    onInterlacedChanged();
    /*vidInfo.RegisterVidPropertyListener();
    vidInfo.RegisterSignalAndPresenceListener();
    vidInfo.RegisterThreeDChangeListener();*/
    if (ControlUnit.flag) {
    GetParams = vidInfo.GetVideoProperty();
    Log.i("TvPlayerFunctionalTestApp","Get Video Property called");
    fieldFrequency = GetParams.fieldFrequency;
    numberOfFrameLines = GetParams.numberOfFrameLines;
    numberOfVisibleLines = GetParams.numberOfVisibleLines;
    numberOfVisiblePixels = GetParams.numberOfVisiblePixels;
    interlace = GetParams.interlace;
    imageFormat = GetParams.imageFormat;
    videoCoding = GetParams.videoCoding;
    scanType = GetParams.scanType;
    }

   /* tv.setText("Something");
    tv.setLayoutParams(textViewParams);
    lv.addView( tv );*/
}

@Override
protected void onStop() {
    // TODO Auto-generated method stub
    super.onStop();
    /*vidInfo.UnRegisterSignalAndPresenceListener();
    vidInfo.UnRegisterThreeDChangeListener();
    vidInfo.UnRegisterVidPropertyListener();*/
}
public void onFieldFrequencyChanged(){

    String info = "On field frequency changed , value is " + vidInfo.ChangedFrequency;

    tv = new TextView(this);
    tv.setText(String.valueOf(info));
    LinearLayout.LayoutParams textViewParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    tv.setLayoutParams(textViewParams);
    lv.addView(tv);
}
public void onImageFormatChanged() {

    String info = "On Image Format  changed , value is " + vidInfo.ChangedFormat;
    tv1 = new TextView(this);
    tv1.setText(String.valueOf(info));
    LinearLayout.LayoutParams textViewParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    tv1.setLayoutParams(textViewParams);
    lv.addView(tv1 );
}
public void onInterlacedChanged() {

    String info = "On Interlaced  changed , value is " + vidInfo.InterlaceChange;
    tv.setText(String.valueOf(info));
    LinearLayout.LayoutParams textView
Params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    tv.setLayoutParams(textViewParams);
    lv.addView(tv);
}
4

4 回答 4

3

只需声明具有垂直方向的线性布局

       <LinearLayout
         android:id="@+id/linear"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

     LinearLayout lv = (LinearLayout)findViewById(R.id.linear);
      TextView tv = new TextView(this);

  tv.setLayoutParams(InformationActivity.textViewParams);
  tv.setText(String.valueOf(info));
  lv.addView(tv );//not InformationActivity.tv just write tv

它将自动在另一个视图下方添加下一个视图

于 2013-09-23T06:17:44.617 回答
0

确保您LinearLayout的方向设置为垂直。然后再添加一项:

LinearLayout layout = // your layout
TextView textView = // new text view
layout.addView(textView);
于 2013-09-23T06:18:59.060 回答
0

只需制作一个Linear Layout其方向是垂直的并添加TextView到它。

于 2013-09-23T06:19:44.053 回答
0

您需要来自主 ViewGroup 的对象(RelativeLayout、LinearLayout 等),

TextView text = new TextView(this);     RelativeLayout r = (RelativeLayout)findViewById(Id);r.add(text);

这行代码将在 r viewGroup 的末尾添加一个新的 textView 对象。

于 2013-09-23T06:27:20.507 回答