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