Java 如何为我的android应用程序制作表格
我想为我的android应用程序制作这样的表格(如图所示)。但我想不出来。我怎么做?Java 如何为我的android应用程序制作表格,java,android,xml,native,Java,Android,Xml,Native,我想为我的android应用程序制作这样的表格(如图所示)。但我想不出来。我怎么做? 请给我一些例子或技巧,将帮助我做这个表 您可以使用tablelayout。请参见此示例,您可以使用LinearLayout以及属性Layout\u weight获得所需的布局。但随着您对表格布局的熟悉程度越来越高 TableLayout: <?xml version="1.0" encoding="utf-8"?> 一个两个表格行按照SO布局显示,您可以从这里开始更长的时间。非常简单
请给我一些例子或技巧,将帮助我做这个表 您可以使用tablelayout。请参见此示例,您可以使用
LinearLayout
以及属性Layout\u weight
获得所需的布局。但随着您对表格布局的熟悉程度越来越高
TableLayout:
<?xml version="1.0" encoding="utf-8"?>
一个两个
表格行
按照SO布局显示,您可以从这里开始更长的时间。非常简单。android:layout weight
属性应该可以完成这项工作。
但是您还需要边框,因此我们必须创建一个可绘制的,以便在/res/drawable文件夹中为TextView
s设置背景:
bg.xml
这是活动的xml
layout_main.xml
这就是它的样子:
希望这就是你想要的代码>它应该是固定大小或动态的,就像ListViee一样?你也想要边框吗?它应该是动态的@Eldar MensutovYes我想要完全像图片@SMRyou会投票并接受的谢谢…这对我非常有帮助:)@Vikalp Patelh我如何管理text4和text5之间的边框@维卡普Patel@jubayer_sust:请查看我的更新答案,其中在text4和text5之间添加了额外的字符,使您具有相同的边框
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:shrinkColumns="2"
android:stretchColumns="2" >
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Text1" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Text2" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Text3" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Text4" />
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="@android:color/black"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Text5" />
</LinearLayout>
</TableRow>
</TableLayout>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<stroke
android:width="2dp"
android:color="#000" />
</shape>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/bg"
android:gravity="center"
android:text="@string/hello_world" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/bg"
android:gravity="center"
android:text="@string/hello_world" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/bg"
android:gravity="center"
android:text="@string/hello_world" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@drawable/bg"
android:gravity="center"
android:text="@string/hello_world" />
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@drawable/bg"
android:gravity="center"
android:text="@string/hello_world" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/bg"
android:gravity="center"
android:text="@string/hello_world" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@drawable/bg"
android:gravity="center"
android:text="@string/hello_world" />
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@drawable/bg"
android:gravity="center"
android:text="@string/hello_world" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/bg"
android:gravity="center"
android:text="@string/hello_world" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@drawable/bg"
android:gravity="center"
android:text="@string/hello_world" />
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@drawable/bg"
android:gravity="center"
android:text="@string/hello_world" />
</LinearLayout>
</LinearLayout>
</LinearLayout>