九.网格、帧、表格布局

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

滑动前.png

滑动后.png

<?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;
            }
        });
    }
}
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 看了几篇文章以及自己写了一些,关于布局的问题,根据别人的写作总结一下得到 一.基本理论Android六大基本布局分...
    shuaikun阅读 883评论 0 4
  • 翻译自“Collection View Programming Guide for iOS” 0 关于iOS集合视...
    lakerszhy阅读 4,077评论 1 22
  • 一.四大组件: Android四大组件分别为activity、service、content provider、b...
    Near尼尔阅读 2,312评论 1 12
  • 今天我读的书是《鸟奴》我看了161页到170页,里面的内容是:头一次飞翔。就飞的这么潇洒,这么漂亮,这么成功,毫无...
    杨浩然五三阅读 247评论 0 0
  • 昨晚忘记更文了。今天早上醒来才记起来。好在有复活卡。 要是人生也有复活的机会,我想我会尝试很多不同的事情吧。 今天...
    楚南之获阅读 681评论 1 3

友情链接更多精彩内容