0

我尝试使用按钮、图像视图和视频视图制作滚动视图。

我从我的代码动态创建。

当我按下带视频的按钮时,我可以看到它们。button 和 imageView 也是如此。

我的问题是当有 videoView 和 imageView 时。当我同时拥有它们时,我看不到 VidoView,我只看到 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();
        }
    }           
4

1 回答 1

0

这可能是因为您的 LayoutParams 的大部分高度都为LayoutParams.MATCH_PARENT. “MATCH_PARENT”表示您希望此元素的高度与父容器一样大。不知道你究竟想要完成什么布局,所以除了首先尝试将宽度设置为 WRAP_CONTENT 并从那里获取之外,我不推荐修复。

于 2013-05-18T22:54:48.757 回答