7th Section Tablelayout
TableLayout
As the name implies, it is a table-like layout. It is a LinearLayout
subclass, so it has TableLayout
all the properties.
7.1
TableLayout
The number of rows
TableLayout
A subclass that needs to be used in conjunction with its partner, TableRow
TableRow
LinearLayout
representing each row of the table, such as a table with 3 rows, the layout file should look like this,
< Tablelayout android:layout_height = "Match_ Parent " android:layout_width =" match_parent " ; <tablerow /> <!--first line--> <tablerow /> <!--second row--> < TableRow /> <!--third row--> </tablelayout ;
TableRow
You can not specify its android:layout_height
and android:layout_width
properties (for other types of layouts, these two properties must be set, or the compiler will prompt for errors), by default, for android:layout_height
wrap_content
android:layout_width
match_parent
.
7.2
TableLayout
The number of columns
The number of TableRow
child controls (or sub-layouts) contained in each of these are the columns of the table. If the number of TableRow
child controls contained in each individual is not the same, then the maximum number of children is the same as the column count for the entire table.
For example, the following layout,
<tablelayoutandroid:layout_height="Match_parent"android:layout_ Width="Match_parent"> <TableRow > <button android:text="C"/> <button android:text="DEL"/> <button android:text="." /> <button android:text="+"/> </TableRow> <TableRow > <button android:text="7"/> <button android:text="-"/> </TableRow> <TableRow > <button android:text="4"/> <button android:text="5"/> <button android:text="6"/> </TableRow> <TableRow > <button android:text="1"/> <button android:text="2"/> <button android:text="3"/> <button android:text="/"/> </TableRow> <TableRow > <button android:text="0" /> </TableRow></tablelayout>
The effect is as follows, you can see that this is a 5*4 table, some rows have 2, some 3, some 4, so the number of the most used as a table column. This is because the screen space is relatively large, and does not occupy the entire screen.
7.3
TableLayout
Interface adjustment 7.3.1 Divide the table
Most of the time, we want each row of the table to have an average allocation of available space, so you can TableRow
set the android:layout_weight=1
<tablelayoutandroid:layout_height="Match_parent"android:layout_width ="Match_parent"> <TableRow android:layout_weight="1"> <button android:text="C"/> <button android:text="DEL"/> <button android:text="." /> <button android:text="+"/> </TableRow> <TableRow android:layout_weight="1"> <button android:text="7"/> <button android:text="-"/> </TableRow> <TableRow android:layout_weight="1"> <button android:text="4"/> <button android:text="5"/> <button android:text="6"/> </TableRow> <TableRow android:layout_weight="1"> <button android:text="1"/> <button android:text="2"/> <button android:text="3"/> <button android:text="/"/> </TableRow> <TableRow android:layout_weight="1"> <button android:text="0" /> </TableRow></tablelayout>
Each column of the table distributes the available space evenly, so it can be added for each, TableLayout
android:stretchColumns="*"
so that the remaining space is stretched equally,
<TableLayout android:layout_height="match_parent" android:layout_width="match_parent" android:stretchColumns="*"> ......</TableLayout>
android:stretchColumns
Used to specify the cells that need to be stretched, *
representing all cells.
You can also specify a partial cell stretch, such as specifying 2nd Lech 4th column,
<TableLayout android:layout_height="match_parent" android:layout_width="match_parent" android:stretchColumns="1,3">
Note that the number of cells that can be stretched is from the 0
beginning, and multiple cells can be separated by commas.
7.3.2 Shrinking of table columns
Sometimes, if the contents of a cell are too long, it affects the display of other columns in the same row, for example,
<tablelayoutandroid:layout_height="Match_parent"android:layout_width ="Match_parent"> <TableRow android:layout_weight=1> <button android:text="Cfdfdfdfdffdfdffdfdffdfdfdfdfdfdfddf"/> <button android:text="DEL"/> <button android:text="." /> <button android:text="+"/> </TableRow>......</tablelayout>
If it is TableLayout
used android:shrinkColumns
, and specifies a column that can be shrunk, 0
then the contents of this list can be stretched toward the bottom,
<TableLayout android:layout_height="match_parent" android:layout_width="match_parent" android:shrinkColumns="0"> ......</TableLayout>
Note that the number of cells that can be shrunk is from the 0
beginning, and multiple cells can be separated by commas.
7.3.3 The table column is hidden
To hide a column is also easy to use, fill in the ordinal of the column you want to android:collapseColumns
hide, for example,
<TableLayout android:layout_height="match_parent" android:layout_width="match_parent" android:collapseColumns="0"> ......</TableLayout>
As you can see, the first column has been hidden and gone.
Note that the number of cells that can be shrunk is from the 0
beginning, and multiple cells can be separated by commas.
7.3.4 cross-columns of cells
Sometimes, you want a button to span multiple columns, you can use android:layout_span
properties, such as here to let 0
the keys, across two columns
<tablelayout android:layout_height = "match_parent" android:layout_width =; ... Span class= "Hljs-tag" ><tablerow android:layout_ Weight = "1" ; < button android:text = "0" android:layout_span =" 2 "/> </tablerow ; ... </tablelayout ;
It is important to note that the TableLayout
cells in are not merged across rows.
8th Section Videoview
Play video You can use the ready-made controls provided by the Android SDK VideoView
. It is the right media player
and surface
the package, for the first time for the development of video playback developers, use VideoView
is the simplest and convenient, do not pay attention to the details of the implementation of the way.
Use of 8.1 videoview
VideoView
The use of, very simple,
Place a control in the layout file VideoView
,
<VideoView android:id="@+id/video_view" android:layout_width="match_parent" android:layout_height="match_parent"/>
In activity, get the layout file VideoView
, then set the video address to play,
mVideoView = (VideoView) findViewById(R.id.video_view);//使用视频的字符串路径mVideoView.setVideoPath(strPath);//使用视频的uri路径mVideoView.setVideoURI(uriPath);
- Using a string path, the video's address is similar to:
/storage/emulated/0/Video/【大自然】mothernature(蒋雯丽配音).mp4
;
- Use URI path;
VideoView
control the flow of video playback using the provided interface,
//从头开始播放视频mVideoView.start();//暂停播放视频mVideoView.pause();//继续播放视频mVideoView.resume()//跳转到xxx毫秒处开始播放mVideoView.seekTo(xxx);
8.2 Control Panel
You can also VideoView
add Control Panel- MediaController
This panel integrates the play progress drag, pause, resume playback and other functions, but also can be automatically hidden or displayed.
Using the Android SDK comes with MediaController
,
new MediaController(context);mVideoView.setMediaController(controller);
If you VideoView
have a parent layout, the one you add to it is attached to the MediaController
bottom of the parent layout.
Therefore, in order to look good, often in the layout file, will be VideoView
placed in a separate FrameLayout
, and let it center display,
< Framelayout android:layout_width = "Match_ Parent " android:layout_height =" match_parent "; <videoview android:layout_gravity =" center " Android:id = "@+id/video_view" android:layout _width = "match_parent" android:layout_height = "match_parent" /> </ framelayout ;
Layout and controls (vi)-tablelayout and Videoview