java制作九行九列表格_九.网格、帧、表格布局

本文介绍了Java中如何创建九行九列的表格布局,详细讲解了`TableLayout`的特性,如设置单元格大小、扩展和收缩列。接着探讨了`GridLayout`的使用,包括组件排列、对齐方式和行列设置。同时,还分析了`FrameLayout`的布局特点,如对象定位、覆盖显示,并提供了触屏事件响应的代码示例,演示了如何通过触摸事件改变布局中组件的可见性。
摘要由CSDN通过智能技术生成

表格布局(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.手指滑动屏幕验证案例

317b37bccb18

滑动前.png

317b37bccb18

滑动后.png

android:layout_width="match_parent"

android:layout_height="match_parent"

android:id="@+id/layout">

android:id="@+id/textView2"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:gravity="center"

android:text="@string/finish" />

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"/>

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;

}

});

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值