我的主要活动窗口看起来非常丑陋。自从我尝试并研究了一个教程以来,我的最后一部分是将尺寸设置为全屏显示(人像/风景)
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="521dp"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
android:fillViewport="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/spinner">
<HorizontalScrollView
android:id="@+id/hscrll1"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/RelativeLayout1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:orientation="vertical">
<TableLayout
android:id="@+id/table_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:stretchColumns="0">
</TableLayout>
</RelativeLayout>
</HorizontalScrollView>
</ScrollView>
在此表布局中添加行正在动态进行,并且代码显示如下:
// border
GradientDrawable gd = new GradientDrawable();
gd.setColor(Color.WHITE); // Changes this drawbale to use a single
color instead of a gradient
gd.setCornerRadius(5);
gd.setStroke(1, 0xFF000000);
// draw table header
final TableLayout stk = (TableLayout) findViewById(R.id.table_main);
TableRow tbrow0 = new TableRow(this);
TextView tv0 = new TextView(this);
tbrow0.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,TableRow.LayoutParams.WRAP_CONTENT));
tv0.setText(" Type ");
tv0.setPadding(5, 15, 0, 15);
tv0.setTextColor(Color.BLACK);
tv0.setBackground(gd);
tv0.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.textsize));
tv0.setGravity(Gravity.CENTER);
tbrow0.addView(tv0);
TextView tv1 = new TextView(this);
tv1.setText(" Year ");
tv1.setPadding(5, 15, 0, 15);
tv1.setTextColor(Color.BLACK);
tv1.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.textsize));
tv1.setGravity(Gravity.CENTER);
tv1.setBackground(gd);
tbrow0.addView(tv1);
TextView tv2 = new TextView(this);
tv2.setPadding(5, 15, 0, 15);
tv2.setText(" Month ");
tv2.setTextColor(Color.BLACK);
tv2.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.textsize));
tv2.setGravity(Gravity.CENTER);
tv2.setBackground(gd);
tbrow0.addView(tv2);
TextView tv3 = new TextView(this);
tv3.setPadding(5, 15, 0, 15);
tv3.setText(" Week ");
tv3.setTextColor(Color.BLACK);
tv3.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.textsize));
tv3.setGravity(Gravity.CENTER);
tv3.setBackground(gd);
tbrow0.addView(tv3);
TextView tv4 = new TextView(this);
tv4.setPadding(5, 15, 0, 15);
tv4.setText(" Amount ");
tv4.setTextColor(Color.BLACK);
tv4.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.textsize));
tv4.setGravity(Gravity.CENTER);
tv4.setBackground(gd);
tbrow0.addView(tv4);
stk.addView(tbrow0);
即使有太多代码,该控件仍然看起来像下面的图所示那样放置错误:
任何人都可以看看我的主要活动,并告诉我我在做什么错。
最终输出应该是表在行与行之间具有相同的行宽和高度大小
答案 0 :(得分:0)
只需将活动更改为此即可解决问题
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="613dp"
android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="@+id/spinner"
tools:layout_editor_absoluteX="0dp">
<TableLayout
android:id="@+id/table_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="0dp"
android:stretchColumns="*"></TableLayout>
</ScrollView>