3.29

所花时间:2小时

代码量:154

博客篇:1

自定义表格

重写onDraw方法

package com.example.studyapplication;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.widget.TextView;

/**
 * 自定义TextView
 */
public class MyTableTextView extends androidx.appcompat.widget.AppCompatTextView {

    Paint paint = new Paint();

    public MyTableTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        int color = Color.parseColor("#80b9f2");
        // 为边框设置颜色
        paint.setColor(color);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        // 画TextView的4个边
        canvas.drawLine(0, 0, this.getWidth() - 1, 0, paint);
        canvas.drawLine(0, 0, 0, this.getHeight() - 1, paint);
        canvas.drawLine(this.getWidth() - 1, 0, this.getWidth() - 1, this.getHeight() - 1, paint);
        canvas.drawLine(0, this.getHeight() - 1, this.getWidth() - 1, this.getHeight() - 1, paint);
    }
}

  

table.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="match_parent">

    <com.example.studyapplication.MyTableTextView
        android:id="@+id/list_1_1"
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/list_1_2"
        android:layout_alignTop="@+id/list_1_2"
        android:gravity="center"
        android:textColor="#000"
        android:textSize="13sp" />

    <com.example.studyapplication.MyTableTextView
        android:id="@+id/list_1_2"
        android:layout_width="180dp"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/list_1_1"
        android:gravity="center"
        android:textColor="#000"
        android:textSize="13sp" />

    <com.example.studyapplication.MyTableTextView
        android:id="@+id/list_1_3"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/list_1_2"
        android:layout_alignTop="@+id/list_1_2"
        android:layout_toRightOf="@+id/list_1_2"
        android:gravity="center"
        android:textColor="#000"
        android:textSize="13sp" />

    <com.example.studyapplication.MyTableTextView
        android:id="@+id/list_1_4"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/list_1_3"
        android:layout_alignBottom="@+id/list_1_3"
        android:layout_toRightOf="@+id/list_1_3"
        android:gravity="center"
        android:textColor="#000"
        android:textSize="13sp" />

    <com.example.studyapplication.MyTableTextView
        android:id="@+id/list_1_5"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/list_1_4"
        android:layout_alignTop="@+id/list_1_4"
        android:layout_toRightOf="@+id/list_1_4"
        android:gravity="center"
        android:textColor="#000"
        android:textSize="13sp" />

    <com.example.studyapplication.MyTableTextView
        android:id="@+id/list_1_6"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/list_1_5"
        android:layout_alignTop="@+id/list_1_5"
        android:layout_toRightOf="@+id/list_1_5"
        android:gravity="center"
        android:textColor="#000"
        android:textSize="13sp" />


    <com.example.studyapplication.MyTableTextView
        android:id="@+id/list_1_7"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/list_1_6"
        android:layout_alignTop="@+id/list_1_6"
        android:layout_toRightOf="@+id/list_1_6"
        android:gravity="center"
        android:textColor="#000"
        android:textSize="13sp" />
</RelativeLayout>

  

活动使用的xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/main"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".statsFinal">

    <Button
        android:id="@+id/bt_final"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="查询"/>
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        android:scrollbars="none"
        >

        <HorizontalScrollView
            android:id="@+id/scroll_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scrollbarAlwaysDrawHorizontalTrack="false"
            android:scrollbars="none">

            <LinearLayout
                android:id="@+id/MyTable"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="9dp"
                android:orientation="vertical"
                >
            </LinearLayout>

        </HorizontalScrollView>
    </ScrollView>
</LinearLayout>

  

posted @ 2024-03-29 20:33  umiQa  阅读(4)  评论(0编辑  收藏  举报