Android将表格布局扩展到整个页面
我试图让我的表格布局在整个页面上展开。现在所有的表格行都被“推”在一起。但我想让他们分开得更远 目前情况: 我想要达到的目标: java(添加此项是因为我正在动态添加TableRows)Android将表格布局扩展到整个页面,android,android-tablelayout,Android,Android Tablelayout,我试图让我的表格布局在整个页面上展开。现在所有的表格行都被“推”在一起。但我想让他们分开得更远 目前情况: 我想要达到的目标: java(添加此项是因为我正在动态添加TableRows) 公共类FoundLocationsActivity扩展了AppCompativeActivity{ int tableRows=0; @凌驾 创建时受保护的void(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setCont
公共类FoundLocationsActivity扩展了AppCompativeActivity{
int tableRows=0;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.foundlocations);
这个.fillTable();
}
私有void fillTable(){
//获取表格布局
TableLayout TableLayout=(TableLayout)findViewById(R.id.TableLayout);
//做柱子
字符串[]列=新字符串[3];
列[0]=“体育学校”;
列[1]=“Afstand”;
列[2]=“分数”;
this.addTableRow(tableLayout,columns);
//插入硬编码的位置(目前)。
字符串[]fitar=新字符串[3];
fitar[0]=“fitar”;
fitar[1]=“12公里”;
fitar[2]=“5.0”;
字符串[]rodea=新字符串[3];
rodea[0]=“rodea”;
rodea[1]=“6公里”;
rodea[2]=“4.0”;
字符串[]mostreu=新字符串[3];
mostreu[0]=“mostreu”;
mostreu[1]=“30公里”;
mostreu[2]=“3.0”;
addTableRow(表格布局,fitar);
addTableRow(表格布局,rodea);
addTableRow(tableLayout,mostreu);
}
私有void addTableRow(TableLayout TableLayout,字符串[]文本){
TableRow TableRow=新的TableRow(本);
tableRow.setLayoutParams(新的tableRow.LayoutParams(TableLayout.LayoutParams.MATCH_父项,tableRow.LayoutParams.MATCH_父项));
for(int i=0;i
layout.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="150dp">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="131dp"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"
app:toolbarId="@+id/toolbar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"></android.support.v7.widget.Toolbar>
<ImageView
android:id="@+id/imageView3"
android:layout_width="68dp"
android:layout_height="83dp"
android:layout_gravity="left|center"
android:layout_marginLeft="30dp"
app:srcCompat="@drawable/logo_rood" />
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="20dp"
android:gravity="bottom|center_horizontal"
android:text="CONFIDENTIAL"
android:textColor="@color/colorAccent" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="Sportscholen die voldoen aan uw criteria:"
android:textAlignment="center"
android:textColor="@color/colorAccent"
android:textSize="18sp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TableLayout
android:id="@+id/tableLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView2"></TableLayout>
</android.support.constraint.ConstraintLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
提前谢谢 如果确认只使用3列,那么为什么不在.xml文件中设置大小?使用类似于:
<TableRow>
<TextView>
set your size
</TextView>
</TableRow>
设定你的尺寸
我用这个答案解决了这个问题:
在your layout.xml中,将以下内容添加到TableLayout中:
<TableLayout
android:stretchColumns="0,1,2"
</TableLayout>
你好,Zainub,我不知道这将如何解决我的问题。所有的文字只会变得更大。但我希望利润更大。每列需要屏幕宽度的33%。您也可以调整字体大小。我想是吧,但我不是问这个。
<TableLayout
android:stretchColumns="0,1,2"
</TableLayout>