表格布局(TableLayout)
1.可以在行中间添加单元格
android:layout_span="2" //占多少列layout_span
android:layout_column="2" //layout_column指明在索引为2的列数
android:stretchColumns="1" //stretchColumns扩展索引为1的按钮单元格1,单元格顺序基数0开始
android:shrinkColumns="1" //shrinkColumns文本过长,索引为1的按钮自动收缩
android:collapseColumns="1" //collapseColumns索引为1的一列隐藏(折叠)
网格布局(GridLayout)
1.设置组件的排列方式:
android: orientation="vertical/horizontal"
2.设置组件的对齐方式: android:layout_gravity="center/left/right/buttom/fill"
3.设置布局为几行几列:
设置有多少行:android:rowCount="4" //设置网格布局有四行
设置有多少列:android:columnCount="4" //设置网格布局有四列
帧布局(FrameLayout)
1.显示对象都将会固定在屏幕的左上角,不能指定位置
android:scaleType="fitXY //scaleType:适合于XY
2.当有多个显示对象,后一个将会直接在前一个之上进行覆盖显示,把前一个控件部分或全部挡住(除非后一个是透明的)
3.手指滑动屏幕验证案例
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/layout">
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="@string/finish" />
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/touch"
android:background="@mipmap/finger"
android:gravity="bottom|center_horizontal"
android:layout_marginTop="50dp"
android:layout_marginBottom="50dp"/>
</FrameLayout>
public class MainActivity extends AppCompatActivity {
//声明所需要的控件
private FrameLayout layout;
private TextView textView2,textView3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.framelayout2); //关联所需要的布局
initControl(); //希望能够关联我们的控件(方法)
}
private void initControl() {
layout=(FrameLayout)findViewById(R.id.layout); //findViewById 关联控件
textView2=(TextView)findViewById(R.id.textView2);
textView3=(TextView)findViewById(R.id.textView3);
//触屏事件
//在layout上面触发触屏事件
layout.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_MOVE){
//INVISIBLE:让textView3不可见
textView3.setVisibility(View.INVISIBLE);
//VISIBLE:让textView2可见
textView2.setVisibility(View.VISIBLE);
}
return true;
}
});
}
}