0

我尝试使按钮,imageview和viedoview滚动视图。滚动视图与按钮,ImageView和viedoView

我从我的代码动态创建。

当我把视频按钮,我可以看到他们两个。与button和imageView一样。

我的问题是当videView和imageView。当我有他们两个我不能看到VidoView和我seeo只有imageView。

感谢帮助:)

这里是我的代码:

XML滚动视图代码:

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="fill_parent" 
    android:fillViewport="true" > 

     <RelativeLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" > 

    <LinearLayout 
     android:id="@+id/dateMain" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" > 

    </LinearLayout> 


    </RelativeLayout> 

</ScrollView> 

我的Java代码:

private void addPics() { 

      extras = getIntent().getExtras(); 
      String s = extras.getString("date"); 

      DataBaseMain data = new DataBaseMain(this); 
      data.open(); 
      paths = data.getWorkOutPic(s); 
      data.close(); 

      if(paths == null || paths.length < 1) 
      return; 

      LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); 

      for(int i = 0; i < paths.length; i++){ 

       Bitmap yourSelectedImage = BitmapFactory.decodeFile(paths[i]); 
       ImageButton pic = new ImageButton(this); 
       pic.setImageBitmap(yourSelectedImage); 
       pic.setAdjustViewBounds(true); 
       pic.setLayoutParams(lp); 
       pic.setId(i); 
       pic.setOnLongClickListener(new OnLongClickListener() { 
        public boolean onLongClick(View arg0) {    
         selectedPictrue = arg0.getId(); 
         onButtonClickEvent(arg0); 
         return true; 
        } 
       }); 
      linear.addView(pic); 
      } 

      } 

     private void addVideos() { 

      extras = getIntent().getExtras(); 
      String s = extras.getString("date"); 

      DataBaseMain data = new DataBaseMain(this); 
      data.open(); 
      videos = data.getWorkOutVideo(s); 
      data.close(); 

      if(videos == null || videos.length < 1) 
      return; 

      LinearLayout linear = (LinearLayout) findViewById(R.id.dateMain); 
      LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); 
      LayoutParams lp2 = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); 

      for(int i = 0; i < videos.length; i++){ 

       Button b = new Button(this); 
       b.setLayoutParams(lp2); 
       b.setText("Delete video"); 
       b.setId(i+50); 
       linear.addView(b); 
       b.setOnClickListener(this); 

       VideoView video = new VideoView(this); 
       video.setVideoPath(videos[i]); 
       video.setLayoutParams(lp); 
       video.setId(i+50); 
       video.setMediaController(new MediaController(this)); 
       video.bringToFront(); 
       linear.addView(video); 
      }   
     } 

     public void setLogView(String date){ 


     DataBaseMain dataBase = new DataBaseMain(this); 
     dataBase.open(); 
     all = dataBase.dayLog(date); 
     dataBase.close(); 

     if (all == null || all[0].length < 1 || all[3][0] == null || all[3][0].equals("")) 
      return; 

     LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); 

     for (int i = 0; i < all[0].length; i++){ 
      String temporay = ""; 

      for(int j = 0; j < all.length; j++) 
       { 
        temporay = temporay + " " + all[j][i]; 
       } 

      Button mine = new Button(this); 
      mine.setText(temporay); 
      mine.setTextColor(getResources().getColor(R.color.black)); 
      mine.setBackgroundColor(color.transparent); 
      mine.setLayoutParams(lp); 
      mine.setId(i); 
      mine.setOnClickListener(this); 
      linear.addView(mine); 
      //Toast.makeText(this, ""+i, Toast.LENGTH_SHORT).show(); 
     } 
    }   

回答

0

这可能是因为你有最您的LayoutParams高度达到LayoutParams.MATCH_PARENT。 “MATCH_PARENT”表示您希望此元素的高度与父容器一样大。不确定你正在尝试完成布局的明智之举,所以除了首先试图将宽度设置为WRAP_CONTENT并从中取出它之外,我不建议进行修复。

+0

我想创建包含按钮,视频和图像浏览的布局。 – tomer