美文网首页
Media Images Video and Sound

Media Images Video and Sound

作者: LeonaLiu | 来源:发表于2017-02-17 14:53 被阅读0次

    小发现

    • imageView 有个onClick的属性;
    • imageView 的动画方法 animate(), translation打头的是移动含义;
    counter.animate().translationYBy(1000f).rotation(360).setDuration(300);
    //1000f 的f是float的意思,因为参数要求float类型
    
    • VideoView可以用来播放视频,以下是demo代码
            VideoView videoView = (VideoView) findViewById(R.id.videoView);
            videoView.setVideoPath("android.resource://" + getPackageName() + "/" + R.raw.demovideo);
    
            MediaController mediaController = new MediaController(this);
    
            mediaController.setAnchorView(videoView);
    
            videoView.setMediaController(mediaController);
    
            videoView.start();
    
    • MediaPlayer用于播放音频,可以关联 seekBar 来控制进度 和 音量,以下是demo代码
            MediaPlayer mplayer = MediaPlayer.create(this, R.raw.laugh);
    
            audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
            int maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
            int curVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
    
            SeekBar volumeControl = (SeekBar)findViewById(R.id.seekBar);
            volumeControl.setMax(maxVolume);
            volumeControl.setProgress(curVolume);
    

    GridLayout的一些小技巧

    • GridLayout中的* layout_column,layout_row,layout_columnWeight,layout_rowWeight,layout_gravity,orientation,columnCount,rowCount*

    1. 如果API21以上是可以直接使用,以 android:开头

    <GridLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentTop="true"
            android:layout_alignParentStart="true">
    
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="0"
                android:layout_row="0"
                android:layout_columnWeight="1"
                android:layout_rowWeight="1"
                android:layout_gravity="fill"
                android:text="Hello"
                android:onClick="buttonTapped"
                android:id="@+id/hello" /> 
    
    </GridLayout>
    

    2. 如果是API 21 以下的,以上提到的属性,需用support 库:com.android.support:gridlayout-v7:24.2.1',还要把上述属性改为app:及tag名称修改。

       <android.support.v7.widget.GridLayout
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:columnCount="2"
            app:rowCount="4"
            app:orientation="vertical"
            >
    
           <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:layout_column="0"
                app:layout_row="0"
                app:layout_columnWeight="1"
                app:layout_rowWeight="1"
                app:layout_gravity="fill"
                android:text="Hello"
                android:onClick="buttonTapped"
                android:id="@+id/hello" />
    
     </android.support.v7.widget.GridLayout>```

    相关文章

      网友评论

          本文标题:Media Images Video and Sound

          本文链接:https://www.haomeiwen.com/subject/jptlwttx.html