使用Button,ImageView和viedoView滚动视图

时间:2013-05-18 22:33:39

标签: android android-layout android-imageview android-scrollview android-video-player

我尝试使用button,imageview和viedoview制作滚动视图。

我是从代码中动态创建的。

当我按下视频按钮时,我可以看到它们。与button和imageView相同。

我的问题是有videView和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();
        }
    }           

1 个答案:

答案 0 :(得分:0)

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